Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QFileDialog::getExistingDirectoryUrl opening remote dirs
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 :
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
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
QStringfor the path and returns a
QString. The second one uses
QUrlfor both it's starting path and returns a
They both do the same thing because
/homeis 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:.
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
See QUrl docs for details on forming and using QUrl and schemes.
A ha! Now it all makes sense. This makes it clear. Thanks a lot.