Solved QFileDialog::getExistingDirectoryUrl opening remote dirs
-
Hi,
I can't seem to find the difference between the two flavors of the static methods provided by QFileDialog. The docs state that the QUrl flavor can even work on remote files/directories but can't seem to see the differences in the dialogs generated by the code snippets below :First
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
Second
QUrl url = QFileDialog::getExistingDirectoryUrl(this, tr("Open Directory"));
The Displayed dialog looks like this (Windows)
Would be great if somebody helped clarify. I must be missing something here.
-
The first one takes a
QString
for the path and returns aQString
. The second one usesQUrl
for both it's starting path and returns aQUrl
.They both do the same thing because
/home
is not a valid path on windows for the first one so you get your last set directory (D: based on the screen shot). In the second example you don't set a starting path/url so you get the same thing which is D:. -
@ambershark
Thanks for the reply. Sorry for my messy code snippets, it was a quick run to see how these methods work. What I really want to know is what they mean by"The main difference with QFileDialog::getExistingDirectory() comes from the ability offered to the user to select a remote directory"
In the doc. Is there any indication in the UI that the user can choose a remote directory? is there needed settings to pass in to have the dialog provide that ability ? Basically a simple code example of how to use this method to select remote dirs would clear the fog a bit. -
@musimbate Oh I understand... so with a QUrl you can use any type of protocol for remote access.. For instance you could use ftp. So you could set up a dialog like:
auto url = QFileDialog::getExistingDirectoryUrl(this, tr("Open Directory"), QUrl("ftp://my.ftp.com"));
You can limit the protocols you allow but setting them as
supportedSchemes
too.See QUrl docs for details on forming and using QUrl and schemes.
-
@ambershark
A ha! Now it all makes sense. This makes it clear. Thanks a lot.