Want a QFileDialog that displays only executable files, but QDir::Filter values are used differently by QFileDialog than by QDir::entryInfoList(..)
-
I am trying to create a QFileDialog where only executable files are displayed in the list of selectable files.
QDir myQDir("/home/user01/filtertest");
QFileDialog myQFileDialogExecutable;
myQFileDialogExecutable.setOptions( QFileDialog::DontUseNativeDialog ); // Need this, otherwise all files are shown.
myQFileDialogExecutable.setDirectory( myQDir );
QFileInfoList dirListExecutable = myQDir.entryInfoList( QDir::Files | QDir::Executable );
myQFileDialogExecutable.setFilter( QDir::Files | QDir::Executable );However, when I call
myQFileDialogExecutable.exec()
only files that are neither readable nor writable are shown. (Not a very common type of file!)
On the other hand, the QFileInfoList returned by
myQDir.entryInfoList( QDir::Files | QDir::Executable );
does return a list with only the executable files in the directory, which is what I expect.
I am hoping someone can point me in the direction of the place in the source code where the filters are applied (for both QFileDialog and QDir::entryInfoList) and/or that someone can give me advice on how to get what I want: a QFileDialog that only displays executable files (on Linux).
I have also tried with different combinations of r/w/x permissions (set the same for user/group/world). I have 8 files in the directory, which I will identify based on their permissions for simplicity: r, rw, rwx, rx, wx, w, x, 000. (Yes, the last four are not permissions you would expect to find in the wild, but I wanted to see how they were treated by the filters.)
Filter: ( QDir::Files | QDir::Readable )
entryInfoList contains: r, rw, rwx, rx -> "must be readable"
QFileDialog returns: r, 000 -> "may not be writable or executable"Filter: ( QDir::Files | QDir::Writable )
entryInfoList contains: rwx, rw, w, wx -> "must be writable"
QFileDialog returns: w, 000 -> "may not be readable or executable"Filter: ( QDir::Files | QDir::Executable )
entryInfoList contains: rwx, rx, wx, x -> "must be executable"
QFileDialog returns: x, 000 -> "may not be readable or writable"Filter: ( QDir::Files | QDir::Readable | QDir::Writable )
entryInfoList contains: rw, rwx -> "must be readable and writable"
QFileDialog returns: r, rw, w, 000 -> "may not be executable"Filter: ( QDir::Files | QDir::Writable | QDir::Executable )
entryInfoList contains: rwx, wx -> "must be writable and executable"
QFileDialog returns: w, wx, x, 000 -> "may not be readable"Filter: ( QDir::Files | QDir::Readable | QDir::Executable )
entryInfoList contains: rwx, rx -> "must be readable and executable"
QFileDialog returns: r, rx, x, 000 -> "may not be writable"Filter: ( QDir::Files | QDir::Readable | QDir::Writable | QDir::Executable )
or
Filter: ( QDir::Files)
entryInfoList contains: r, rw, rwx, rx, w, wx, x, 000 -> "do not filter"
QFileDialog returns: r, rw, rwx, rx, w, wx, x, 000 -> "do not filter"The pattern is fairly clear: QDir::entryInfoList applies r/w/x filter bits as requirements, but QFileDialog allows the filter bit(s) to be either on or off, and requires the remaining bit(s) to be off. Except in the case where all three are on, in which case the behavior is always the same as if no r/w/x filters were applied at all.
Is this really the intended behavior?
-
Hi,
What version of Qt are you using ?
On what Linux distribution ? -
I am using Qt 5.10.1, on CentOS 7