0

I'm new to learning the Qt library, and I'm having a hard time getting QFileDialog to work properly. I want the user to be able to select a directory but also be able to view the files and folders so they know which directory they should pick. I have seen things similar to this being posted elsewhere but everything I've tried hasn't made any difference in the output.

I've tried creating my own dialog and setting the mode to directory, which says that it should display both files and folders:

    QFileDialog myDialog(this);
    myFileExplorer.setFileMode(QFileDialog::Directory);
    myFileExplorer.setDirectory("C:/");
    QString file = myFileExplorer.exec();

And I've tried using getExistingDirectory as well, but with that function it always only shows the directory as well. Thanks

Jacob Frey
  • 3
  • 1
  • 3
  • Have you tried to pass last input argument to getExistingDirectory equal to 0 ? – Max Go Sep 27 '14 at 19:20
  • It shows files on OS X, but doesn't show files on Windows. It's Qt bug. Maybe, you should to see if it's possible to call required dialog directly from the Win API. Or you need to implement files browsing/selecting yourself. – Max Go Sep 27 '14 at 19:32

1 Answers1

2
QString getExistingDirectory ( QWidget * parent = 0, const QString & caption = QString(),
const QString & dir = QString(), Options options = ShowDirsOnly )

The default options parameter is set to show dirs only, you have to change it to

QFileDialog::DontUseNativeDialog

But unfortunately you won't be able to use native dialog.

Mikołaj Mularczyk
  • 959
  • 12
  • 20
  • interesting, is that Win API doesn't support such kind of options, or it's Qt bug with native dialogs. – Max Go Sep 27 '14 at 19:34
  • 1
    in C# it is called commonOpenFileDialog and it also seems not to support that option. There was a question asked some time ago on stackoverflow - http://stackoverflow.com/questions/8142109/how-can-i-make-commonopenfiledialog-select-folders-only-but-still-show-files - So I believe that is not a Qt bug. – Mikołaj Mularczyk Sep 27 '14 at 19:49
  • Ok that worked, thanks! So ultimately the Win API doesn't support that kind of functionality, so we are stuck using a non-native dialog. – Jacob Frey Sep 27 '14 at 20:42