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 doesn't traverse mounted directories correctly

QFileDialog doesn't traverse mounted directories correctly

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 2.6k Views 2 Watching
  • 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 Offline
    J Offline
    Jeff Barnes
    wrote on last edited by
    #1

    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
    0
    • J Jeff Barnes

      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 Offline
      J Offline
      Jeff Barnes
      wrote on last edited by
      #2

      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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        1
        • SGaistS SGaist

          Hi,

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

          J Offline
          J Offline
          Jeff Barnes
          wrote on last edited by Jeff Barnes
          #4

          @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
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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
            1
            • J Jeff Barnes

              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 Offline
              J Offline
              Jeff Barnes
              wrote on last edited by Jeff Barnes
              #6

              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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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
                3
                • SGaistS SGaist

                  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.

                  J Offline
                  J Offline
                  Jeff Barnes
                  wrote on last edited by
                  #8

                  @SGaist bug filed.

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

                    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
                    0

                    • Login

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