PDA

View Full Version : How to select both files and folders using QFileDialog.



merry
16th February 2011, 12:33
Hi all,

I need a "select folders + files" dialog.

In which using same QFileDialog i can select either file or folder.

Regards
Merry

nikhilqt
16th February 2011, 12:45
Try flags http://doc.qt.nokia.com/latest/qfiledialog.html#FileMode-enum

merry
17th February 2011, 06:54
Yeah, I tried but no use i am able to select files only but nt directories.

nikhilqt
18th February 2011, 15:19
post your code snippet having file dlg operation.

merry
21st February 2011, 07:28
Here is the code:


QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::DirectoryOnly);
QString strFileName = dialog.getOpenFileName(this,tr("Select File"), "", tr("All Files (*.*)"));

nikhilqt
21st February 2011, 09:48
Here is the code:


getOpenFileName(this,tr("Select File"), "", tr("All Files (*.*)"));

getOpenFileName(...) is a static method and has its own instance. The dialog instance created by you with flags won't affect this instance.

why can't you use getExistingDirectory (http://doc.qt.nokia.com/latest/qfiledialog.html#getExistingDirectory) ?

merry
21st February 2011, 10:41
Thanks for the reply.


why can't you use getExistingDirectory ?

using this i am able to select dirs ony not files. I want to make a dialog in which i can able to select both files and dirs .

nikhilqt
21st February 2011, 11:59
you can try this,



QFileDialog* dlg = new QFileDialog(NULL);
dlg->setFileMode(QFileDialog::Directory);
int nMode = dlg->exec();
QStringList strlist = dlg->selectedFiles();

ijab
15th May 2012, 06:21
I also have the same problems, and after searching and trying for some times, I found this solution works. You could try.

http://www.qtcentre.org/threads/34226-QFileDialog-select-multiple-directories?p=220108#post220108