Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Want a QFileDialog that displays only executable files, but QDir::Filter values are used differently by QFileDialog than by QDir::entryInfoList(..)

Want a QFileDialog that displays only executable files, but QDir::Filter values are used differently by QFileDialog than by QDir::entryInfoList(..)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdirqfiledialoglinuxfilters
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbrochmann
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what Linux distribution ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrochmann
        wrote on last edited by
        #3

        I am using Qt 5.10.1, on CentOS 7

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved