PDA

View Full Version : How do show in a QFileDialog all files except the executable files?



bhodi78
27th April 2010, 11:20
The only way I can think of is to make a list, but this way I have to anticipate all possible types of files, that is not possible.


QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("All files except .exe (*.png *.xpm *.jpg *.pdf *.gif ............infinite extensions..........)"));


Anyone has a better idea?
Thank you very much.

Lesiok
27th April 2010, 11:57
Just use QDialog::setFilter not QDialog::setNameFilter

bhodi78
27th April 2010, 12:21
Sorry, I tried as you say, but does not work.



#include <QApplication>
#include <QFileDialog>

int main( int argc, char **argv ) {

QApplication app( argc, argv );
QFileDialog dialog(0);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setFilter(QDir::Files); //<--------------------------All files except executable files.???
dialog.exec();
return 0;
}

Kumosan
27th April 2010, 14:35
dialog.setFilter(QDir::Files); //<--------------------------All files except executable files.???

Very interesting problem. There is a QDir::Readable, a QDir::Writable, and a QDir::Executable. All three must be combined with QDir::Files. If QDir::Files shows all files, why add one of the three? To show all files + readable, writable, and executable files? Would only make sense if QDir::Files alone shows nothing. Or QDir::Files shows all, but the writable, readable, executable flags actually subtract files with those permissions. Looks like a minor documentation bug to me.
Try: dialog.setFilter(QDir::Files|QDir::Readable|QDir:: Writable);
or: dialog.setFilter(QDir::Files|QDir::executable);
Just as an experiment. What is the result?

bhodi78
27th April 2010, 15:56
I tried
dialog.setFilter (QDir:: Files | QDir:: Readable | QDir:: Writable);
and so I see all the files except "exe" but I do not see the folders.
Same problem for these two cases:
dialog.setFilter (QDir:: Dirs | QDir:: Files | QDir:: Readable | QDir:: Writable) and
dialog.setFilter (QDir:: Dirs | QDir:: Files | QDir:: Readable | QDir:: Writable | QDir:: Modified);

Instead
dialog.setFilter (QDir:: Files | QDir:: Executable);
I only see the files. "exe" without all the other folders and files.

Kumosan
27th April 2010, 16:02
So,

dialog.setFilter (QDir:: Files | QDir:: Readable | QDir:: Writable);
goes into the right direction.

I don't know the solution, but I would now try:
dialog.setFilter (QDir::AllDirs| QDir:: Readable | QDir:: Writable)

bhodi78
27th April 2010, 16:19
thanks for your help, but unfortunately it does not work that way. :-(

Kumosan
27th April 2010, 16:33
Looks like a Qt bug to me. According to the assistant:
QDir::AllDirs 0x400 List all directories; i.e. don't apply the filters to directory names.
But the executables are filtered. And of course, folders are executable, else it would be impossible to enter them.
At least under Linux.

bhodi78
28th April 2010, 08:26
Amazing we found a bug in qt ..... and now how do I solve the problem? what do you do in these situations?

Kumosan
28th April 2010, 09:18
Amazing we found a bug in qt ..... and now how do I solve the problem? what do you do in these situations?

If it is really a bug... let's wait for the answer from the Trolls. We simply might have overlooked something. I filed a bug report. ;)