diff --git a/src/filewidgets/kfilewidget.h b/src/filewidgets/kfilewidget.h --- a/src/filewidgets/kfilewidget.h +++ b/src/filewidgets/kfilewidget.h @@ -144,11 +144,18 @@ /** * Sets the file name to preselect to @p name * - * This takes absolute URLs and relative file names. + * This method also handles absolute URLs for historical reasons, but + * for URLs you should use setSelectedUrl() instead. */ void setSelection(const QString &name); /** + * Sets the URL to preselect to @p url + * @since 5.33 + */ + void setSelectedUrl(const QUrl &url); + + /** * Sets the operational mode of the filedialog to @p Saving, @p Opening * or @p Other. This will set some flags that are specific to loading * or saving files. E.g. setKeepLocation() makes mostly sense for diff --git a/src/filewidgets/kfilewidget.cpp b/src/filewidgets/kfilewidget.cpp --- a/src/filewidgets/kfilewidget.cpp +++ b/src/filewidgets/kfilewidget.cpp @@ -1571,12 +1571,16 @@ return; } + setSelectedUrl(urlFromString(url)); +} + +void KFileWidget::setSelectedUrl(const QUrl &url) +{ // Honor protocols that do not support directory listing - if (!u.isRelative() && !KProtocolManager::supportsListing(u)) { + if (!url.isRelative() && !KProtocolManager::supportsListing(url)) { return; } - - d->setLocationText(urlFromString(url)); + d->setLocationText(url); } void KFileWidgetPrivate::_k_slotLoadingFinished()