Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QFileDialog doesn't traverse mounted directories correctly

    General and Desktop
    2
    9
    1386
    Loading More Posts
    • 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.
    • J
      Jeff Barnes last edited by

      On Linux Ubuntu 16.04, QFileDialog does not behave as expected.

      In the Ubuntu File Navigator, I can traverse the mounted drives correctly by double clicking. I can also use the command line to traverse them correctly.

      In my Qt 5.7-based application, when I navigate to the mounted directory, double clicking actually causes the QFileDialog to navigate two directories up. If I click once on the directory and click the "Open" button in QFileDialog, it navigates correctly. Once it is inside the mounted directory, double clicks work correctly to navigate further down.

      Here's the relevant code. Would appreciate any help. Really annoying and confusing to end users.

      MainWindow::MainWindow
      {
      ...
          m_packageFileDialog.setNameFilter("gzipped files (*.gz)");
          m_packageFileDialog.setViewMode(QFileDialog::Detail);
          m_packageFileDialog.setFileMode(QFileDialog::ExistingFile);
      ...
      
          QObject::connect(&m_packageFileDialog, &QFileDialog::directoryEntered, this, &MainWindow::onPackageFileDialogDirectoryEntered);
      
      ...
      }
      
      
      void MainWindow::onPackageFileDialogDirectoryEntered(QString dir)
      {
          QDir directory(dir);
          QStringList nameFilters;
          nameFilters << "*.gz";
          QFileInfoList list = directory.entryInfoList(nameFilters, QDir::AllDirs | QDir::Files, QDir::Time | QDir::DirsLast);
          m_packageFileDialog.selectFile(list.at(0).absoluteFilePath());
      }
      
      
      void MainWindow::on_btnBrowse_clicked()
      {
          QStringList paths;
          if (!validateCdnBasePath())
              return; // error dialog popus up if not valid
          m_packageFileDialog.setDirectory(m_cdnBasePath);
          if (m_packageFileDialog.exec())
              paths = m_packageFileDialog.selectedFiles();
          else
              return;
          if (paths.isEmpty())
              return;
          QString path = paths.at(0);
      ...
      }
      `
      
      J 2 Replies Last reply Reply Quote 0
      • J
        Jeff Barnes @Jeff Barnes last edited by

        Also, when the QFileDialog navigates two directories up, clicking the back arrow on the dialog, puts me in the directory I expected when I double clicked.

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Do you have the same behavior if you compile your application with your distribution provided Qt ?

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

          J 1 Reply Last reply Reply Quote 1
          • J
            Jeff Barnes @SGaist last edited by Jeff Barnes

            @SGaist Thanks for the tip. I had high hopes for it, but after installing the distro qt 5 (5.1) with apt and setting the kit to use it in creator, the bug still exists. I'm pretty sure it worked, because I had to add a CONFIG += c++11 to the .pro file for it to compile with the 5.1 kit. Qt 5.7 kit on this platform didn't need that.

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Because C++11 is a requirement since 5.7.

              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 Reply Quote 1
              • J
                Jeff Barnes @Jeff Barnes last edited by Jeff Barnes

                I found a "workaround" for the bug. Here is a small working example that demonstrates it. There appears to be a race condition in the selectFile() function of QFileDialog. Any chance somebody from the Qt team could investigate it?

                OS: ubuntu 16.04 LTS
                Processor: Intel Core i7
                OS type: 64-bit

                fdhandler.cpp

                #include "fdhandler.h"
                
                #include <QDebug>
                #include <QDir>
                #include <QFileInfoList>
                #include <QStringList>
                
                FDHandler::FDHandler(QFileDialog *dlg, QObject *parent)
                    :   QObject(parent)
                    ,   m_fileDialog(dlg)
                {
                }
                
                void FDHandler::onDirectoryEntered(QString dir)
                {
                    QDir directory(dir);
                    QFileInfoList list = directory.entryInfoList(QStringList() << "*.gz", QDir::AllDirs | QDir::Files, QDir::Time | QDir::DirsLast);
                    //uncomment the following line to work around the bug
                    //qDebug() << list.at(0).absoluteFilePath();
                    m_fileDialog->selectFile(list.at(0).absoluteFilePath());
                }
                

                main.cpp

                #include <QApplication>
                #include <QDebug>
                #include <QFileDialog>
                
                #include "fdhandler.h"
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    QFileDialog fd;
                    fd.setNameFilter("gzipped files (*.gz)");
                    fd.setViewMode(QFileDialog::Detail);
                    fd.setFileMode(QFileDialog::ExistingFile);
                    fd.setDirectory("/mnt");
                    FDHandler handler(&fd);
                    QObject::connect(&fd, &QFileDialog::directoryEntered, &handler, &FDHandler::onDirectoryEntered);
                    if (fd.exec())
                        qDebug() << "file selected";
                    else
                        qDebug() << "file not selected";
                    return a.exec();
                }
                
                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  The best for that is to go to the bug report system. Check there if there's already something about the bug you found. If not please open a new report providing your sample + workaround as well as all details about your setup. If there's already something, don't hesitate to add your findings and code.

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

                  J 1 Reply Last reply Reply Quote 3
                  • J
                    Jeff Barnes @SGaist last edited by

                    @SGaist bug filed.

                    1 Reply Last reply Reply Quote 1
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      Can you share the link ? That will make it easier to find.

                      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 Reply Quote 0
                      • First post
                        Last post