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

Android: QFileDialog setDirectory does not set default directory

    XMLWordPrintable

Details

    • Android

    Description

      User wants to set dialog to open up on predefined location:
      "
      with the introduction of Scoped Storage in Android 11, direct access to directories is no longer possible. As a result, I intended to use the QFileDialog as described in the Qt Documentation.

      See in QStandardPaths:
      On Android 11 and above, public directories are no longer directly accessible in scoped storage mode. Thus, paths of the form "<USER>/DirName" are not returned. Instead, you can use QFileDialog which uses the Storage Access Framework (SAF) to access such directories.

      I would use the QFileDialog to file opening and saving. My aim is for the dialog to initially appear within a predefined location such as 'Documents', 'Downloads', or a distinct folder at the same hierarchy level. Unfortunately, I'm facing a problem where the dialog always opens in the last selected folder, which is not what I want.
      "

      From the R&D we were informed that use of QFileDialog setDirectory should help with users request:
      "
      the file dialog doesn't take the old file scheme paths for public storage into account, so passing them to the file dialog won't work. However, if you have a content url already of a tree, I assume you can use https://doc.qt.io/qt-6/qml-qtquick-dialogs-filedialog.html#currentFolder-prop or https://doc.qt.io/qt-6/qfiledialog.html#setDirectory to set that path and Qt would pass that to the native file dialog as EXTRA_INITIAL_URI. Though, if that doesn't work probably it's a bug.
      "

      User tested this with the attached example and and the default directory does not change.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              axelspoerl Axel Spoerl
              tero.pelkonen Tero Pelkonen
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes