0

I want to let the user choose a folder so I can display and sort its contents somewhere else. The best way to do this seems to be using QFileDialog. Here's a snippet of the code I'm using:

> #include <QFileDialog>
.....
void someEvent(){
QString path = QFileDialog::getExistingDirectoryUrl(this, tr("Choose a Folder"), QDir::home());
}

When I try to compile this I get the error:
no matching function for call to QFileDialog::getExistingDirectoryUrl(MainWindow*, QString, QDir) path = QFileDialog::getExistingDirectoryUrl(this, tr("Choose a Folder"), QDir::home());

Note: I'm running Fedora 25 on this PC and I'm wondering whether that might be the issue?

PerryC
  • 1,233
  • 2
  • 12
  • 28
Sphics
  • 88
  • 1
  • 9
  • 1
    The third parameter should be a `QUrl` (according to the [docs](http://doc.qt.io/qt-5/qfiledialog.html#getExistingDirectoryUrl)), but you are passing a `QDir` – UnholySheep Dec 13 '16 at 14:54
  • 4
    Maybe you wanted to use [`getExistingDirectory`](http://doc.qt.io/qt-5/qfiledialog.html#getExistingDirectory) with `QDir::home().path()` as third parameter? – UnholySheep Dec 13 '16 at 14:56
  • 2
    Or `QDir::homePath()` http://doc.qt.io/qt-4.8/qdir.html#homePath – drescherjm Dec 13 '16 at 14:58
  • I used `getExistingDirectory ` with `QDir::home().path()` as the third parameter and it worked. Thanks @UnholySheep , @drescherjm and @PerryC !! – Sphics Dec 14 '16 at 06:23

1 Answers1

0

You have 2 choices depending on your needs, the first one being the best :

getExistingDirectory :

QString path = QFileDialog::getExistingDirectory(this,tr("Choose a Folder"),QDir::homePath());

getExistingDirectoryUrl :

QUrl url = QFileDialog::getExistingDirectoryUrl(this,tr("Choose a Folder"),QUrl(QDir::homePath()));
QString path = url.toString();
Elcan
  • 814
  • 13
  • 27