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

Non-native FileDialog loses URL schema when filename is manually entered

    XMLWordPrintable

Details

    • 26d963446 (dev), f839b0ae7 (6.7), 53c60c2f9 (6.6), 45479ae9f (tqtc/lts-6.5)

    Description

      The example below is for Windows, but it also reproduces on macOS and Linux
       

      Code

      import QtQuick.Controls.Basic
      import QtQuick.Dialogs
      
      ApplicationWindow {
          width: 800
          height: 600
          visible: true
      
          header: Button {
              text: "Open Dialog"
              onClicked: dlg.open()
          }
      
          FileDialog {
              id: dlg
              options: FileDialog.DontUseNativeDialog
              fileMode: FileDialog.SaveFile
              selectedFile: Qt.url("file:///C:/Test/hello.txt")
              onAccepted: console.log("Accepted", selectedFile)
          }
      
          footer: Label { text: dlg.selectedFile }
      }
      
      

       

      Steps to reproduce

      1. Create the folder, "C:\Test"
      2. Run the code above
      3. Click "Open Dialog"
      4. Click "Save" (or "Open" in Qt 6.5.3, due to QTBUG-105080 )
      5. Click "Open Dialog"
      6. In the text field, replace "hello.txt" with "world.txt"
      7. Click "Save" (or "Open" in Qt 6.5.3, due to QTBUG-105080 )
         

      Expected outcomes (Native dialog)

      Actual outcomes (Non-native dialog)

       

      Fix
      The culprit seems to be at https://github.com/qt/qtdeclarative/blob/v6.6.1/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp#L472: QUrl(currentFolder.path() + ...) does not contain the scheme.

      A more robust setter would be

      QUrl newSelectedFile;
      newSelectedFile.setScheme(currentFolder.scheme());
      newSelectedFile.setPath(currentFolder.path() + u'/' + newFileName);
      setSelectedFile(newSelectedFile);
      

      Attachments

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

        Activity

          People

            hurlevent Oliver Eftevaag
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes