Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
6.2.10, 6.5.3
Description
A simple reproducer:
ApplicationWindow { visible: true width: 400 height: 200 Button { text: "Open" onClicked: dialog.open() } Platform.FileDialog { id: dialog title: "title" fileMode: Platform.FileDialog.SaveFile nameFilters: ["csv file" + " (*.csv)", "text file" + " (*.txt)"] onAccepted: { var n = selectedNameFilter.name var i = selectedNameFilter.index console.log(`Name: ${n}, Index: ${i}`) } // selectedNameFilter.onNameChanged: { // } // selectedNameFilter.onIndexChanged: { // } } }
Run the sample, click button to open FileDialog for the first time, then save file. Even if one selects "save type as" from drop-down, the output to console is "qml: Name: , Index: -1" for the first run. The output is correct from the second run though.
Current workaround:
1. Explicitly bind selectedNameFilter.index, as what is done in:
https://doc.qt.io/qt-6/qml-qtquick-dialogs-filedialog.html#selectedNameFilter-prop
2. Use FileDialog from QtQuick.Dialog module. The non-lab version behaves correctly.
3. Uncomment signal handlers, i.e. trying to read selectedNameFilter properties.
Reason:
QQuickLabsPlatformFileNameFilter *QQuickLabsPlatformFileDialog::selectedNameFilter()
The function to create the selectednameFilter won't be called unless QML tries to READ m_selectedNameFilter. So for the first run, m_selectedNameFilter does not exist yet. Only after the 1st run there is a valid m_selectedNameFilter.
Personally speaking, the behavior of non-lab version is preferable.