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. QFileDialog - about the behavior of "QFileDialog::Directory" and "QFileDialog::ExistingFile".
Forum Update on Monday, May 27th 2025

QFileDialog - about the behavior of "QFileDialog::Directory" and "QFileDialog::ExistingFile".

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 814 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.
  • T Offline
    T Offline
    tyamada
    wrote on last edited by tyamada
    #1

    Firstly, I'm sorry if my English is hard to understand.

    http://doc.qt.io/qt-5/qfiledialog.html#FileMode-enum
    This document descrives that "QFileDialog::Directory" is both files and directories, and "QFileDialog::ExistingFile" is single existing file.
    Then I wrote a minimal sample program like below but I can not understand its behavior.
    (OS is Linux)

    #include <QApplication>
    #include <QFileDialog>
    int main( int argc , char *argv[] ) {
        QApplication app( argc , argv ) ;
        QFileDialog dialog;
        dialog.setFileMode( QFileDialog::Directory ) ;
    //    dialog.setFileMode( QFileDialog::ExistingFile ) ;
        dialog.show() ;
        return app.exec() ;
        
    }
    

    When I use QFileDialog::Directory, only directories are shown in the dialog.
    And when I use QFileDialog::ExistingFile, both files and directories are shown in the dialog.
    It seems that it is contrary to the document.

    Is this a documentation bug?
    Or am I something wrong...?

    Paul ColbyP 1 Reply Last reply
    0
    • T tyamada

      Firstly, I'm sorry if my English is hard to understand.

      http://doc.qt.io/qt-5/qfiledialog.html#FileMode-enum
      This document descrives that "QFileDialog::Directory" is both files and directories, and "QFileDialog::ExistingFile" is single existing file.
      Then I wrote a minimal sample program like below but I can not understand its behavior.
      (OS is Linux)

      #include <QApplication>
      #include <QFileDialog>
      int main( int argc , char *argv[] ) {
          QApplication app( argc , argv ) ;
          QFileDialog dialog;
          dialog.setFileMode( QFileDialog::Directory ) ;
      //    dialog.setFileMode( QFileDialog::ExistingFile ) ;
          dialog.show() ;
          return app.exec() ;
          
      }
      

      When I use QFileDialog::Directory, only directories are shown in the dialog.
      And when I use QFileDialog::ExistingFile, both files and directories are shown in the dialog.
      It seems that it is contrary to the document.

      Is this a documentation bug?
      Or am I something wrong...?

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      @tyamada said in QFileDialog - about the behavior of "QFileDialog::Directory" and "QFileDialog::ExistingFile".:

      And when I use QFileDialog::ExistingFile, both files and directories are shown in the dialog.

      I expect that the dialog is showing directories, so that you can navigate into one of them in order to select an existing file within it.

      Cheers.

      1 Reply Last reply
      2
      • T Offline
        T Offline
        tyamada
        wrote on last edited by
        #3

        Ah, I understood it, thanks!

        But about the behavior of "QFileDialog::Directory", when I use qt4, it displays both files and directories as the document described(and as I expected).
        When I use qt5, it displays only directory.

        So I suspect this is maybe qt5 bug.
        I'll try to report it to bugtracker.

        Thank you very much!

        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