PDA

View Full Version : QFileDialog to only show executable files in Linux



qlands
10th September 2016, 14:58
I have a QFileDialog that I want only to select executable files. Here is the code:


QFileDialog selectFile(this,title);
selectFile.setFilter(QDir::Files | QDir::Executable);
selectFile.setDirectory(path);
selectFile.setFileMode(QFileDialog::ExistingFile);
if (selectFile.exec())
qDebug() << selectFile.selectedFiles();

However I can see all files if I run it in Linux. Any idea how to correct it?

anda_skoa
10th September 2016, 15:47
This is interesting, different implementations bahve differently.

With XDG_CURRENT_DESKTOP=KDE I get all files, as you do.

When I run this with XDG_CURRENT_DESKTOP=GNOME I get no files at all.
When I set the QFileDialog::Options to include DontUseNativeDialog I also get not files at all.

I added QDir::Readable to the filter, now GNOME and Non-Native dialog show programs, but seem to not show scripts that are marked executable.

Edit: ah, I think the two latter are actually the same thing (non-native dialog), just differently styled.

Cheers,
_