Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.3, 6.6.1
-
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
- Create the folder, "C:\Test"
- Run the code above
- Click "Open Dialog"
- Click "Save" (or "Open" in Qt 6.5.3, due to
QTBUG-105080) - Click "Open Dialog"
- In the text field, replace "hello.txt" with "world.txt"
- Click "Save" (or "Open" in Qt 6.5.3, due to
QTBUG-105080)
Expected outcomes (Native dialog)
- Step #4: Console prints "Accepted file:///C:/Test/hello.txt"
- Step #7: Console prints "Accepted file:///C:/Test/world.txt"
Actual outcomes (Non-native dialog)
- Step #4: Console prints "Accepted file:///C:/Test/hello.txt"
- Step #7: Console prints "Accepted /C:/Test/world.txt"
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);