Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70798

Qfiledialog Does Not Correctly Restore the Directory

    XMLWordPrintable

Details

    • Windows
    • 589f9f179cd0f570db22f15941625d911f6b7721 (qt/qtbase/5.12)

    Description

      I am using Qt 4 and Qt 5 with Mingw-w64 as compiler. I have subclassed QFileDialog and in the constructor I restore the dialog state like this:

      QSettings settings("Organization", "Application");
      QVariant state = settings.value("DialogFile");
      restoreState(state.toByteArray());
      

       

      To save the directory when closing I have overwritten the done(int) slot like this:

       

      void DialogFile::done(int returnCode)
      {
          QSettings settings("Organization", "Application");
          settings.setValue("DialogFile", saveState());
          QFileDialog::done(returnCode);
      }
      

       
      This has worked well in Qt 4, but since Qt 5 the directory is not correctly restored when I open the file dialog for the first time. There the dialog displays always the working directory of the application. When I navigate to another directory and open a file there, then the correct directory (the last visited directory) will be displayed as soon as I open the file dialog again.
       
      I have used the debugger to find the reason. QFileDialog::restoreState contains suspicious code. It gets "QUrl currentDirectory" from the state that is passed as argument. This directory URL is correct. But then it refuses to use the correct URL, because in the line

      setDirectoryUrl(lastVisitedDir()->isEmpty() ? currentDirectory : *lastVisitedDir());

      the value of lastVisitedDir() is not empty. It contains the working directory of the application. So the dialog will use the working directory.

      Isn't this completely wrong behaviour? If I call a method to restore a given state, then the state should be used and not another variable containing some supposed (but wrong) last visited directory.

      I wonder why this issue is not reported much more often. Has it something to do with my compiler (Mingw-w64)?

       
      Benjamin

      Attachments

        1. qtbug70798_diag.diff
          5 kB
        2. qtbug70798_filedialog.zip
          20 kB
        3. qtbug70798_log.txt
          1 kB
        4. qtbug70798.zip
          21 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            benjaminbihler Benjamin Bihler
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes