PDA

View Full Version : how select whole directory also in QFileDialog?



aurora
19th October 2011, 05:55
How can i support QFileDialog to open multiple files and folders(Directories)?
I'm wrote following code, It enables only to open files not able to open directories. How can i include Directory also?

QStringList files = QFileDialog::getOpenFileNames(
this,
"Select one or more files to open",
"/home",
"Images (*.png *.xpm *.jpg)");
Please somebody help me....Thanks in advance..

amitahire
19th October 2011, 06:23
QString s = QFileDialog::getOpenFileName(
"/home",
"Images (*.png *.xpm *.jpg)",
this,
"open file dialog"
"Choose a file" );


In the above example, The startup directory is set to "/home" ( or if you using windows -"C:\Win") The file filter is set to "Images (*.png *.xpm *.jpg)". The parent of the file dialog is set to this and it is given the identification name - "open file dialog". The caption at the top of file dialog is set to "Choose a file". If you want to use multiple filters, separate each one with two semi-colons, e.g.
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

NOTE - The code given is a working code from Qt 3. I am not sure whether the funtion definition has changed Qt 3 to Qt 4. PLease check the man pages/ documentation.

Hope this clear it out for you do let me/us know if you need anything more.

aurora
19th October 2011, 07:05
QString s = QFileDialog::getOpenFileName(
"/home",
"Images (*.png *.xpm *.jpg)",
this,
"open file dialog"
"Choose a file" );


In the above example, The startup directory is set to "/home" ( or if you using windows -"C:\Win") The file filter is set to "Images (*.png *.xpm *.jpg)". The parent of the file dialog is set to this and it is given the identification name - "open file dialog". The caption at the top of file dialog is set to "Choose a file". If you want to use multiple filters, separate each one with two semi-colons, e.g.
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"

NOTE - The code given is a working code from Qt 3. I am not sure whether the funtion definition has changed Qt 3 to Qt 4. PLease check the man pages/ documentation.

Hope this clear it out for you do let me/us know if you need anything more.


Thank u...But actual my requirement is the dialog must support opening both MULTIPLE FILES and DIRECTORY...
If i use the code u given, where the list of file names(which is suppose to open) will be stored?

amitahire
19th October 2011, 08:46
Thank u...But actual my requirement is the dialog must support opening both MULTIPLE FILES and DIRECTORY...
If i use the code u given, where the list of file names(which is suppose to open) will be stored?

I searched around a bit and found that QFileDialog cannot by default select multiple files - http://developer.qt.nokia.com/faq/answer/when_the_filemode_is_directoryonly_in_my_qfiledial og_how_can_i_select_multi but by getting hold of other classes.

Check these threads out

http://www.qtcentre.org/threads/34226-QFileDialog-select-multiple-directories

http://www.qtcentre.org/threads/18815-Select-multiple-files-from-QFileDialog

Before posting search in the form first :-). Hope you can solve it.

aurora
19th October 2011, 09:30
Thank u so much...:)