Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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...?



  • @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.



  • 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!


Log in to reply