Closed dialog reappears
Unsolved
QML and Qt Quick
-
I want the file selection dialog to appear when I click on the QML button.
I was able to press the button to display the dialog.
However, if you close the displayed dialog and then click on the window, the dialog reappears.(I did not click the button)
I debugged it and for some reason it says the button was pressed even though I did not click on it.
Why does this phenomenon occur?QML:
Button { id: comBtn background: buttonBackground Rectangle { id: buttonBackground color: "#b7b7b7" implicitWidth: 100 implicitHeight: 40 border.color: "#808080" border.width: 2 } states: [ State { name: "normal" when: !comBtn.down PropertyChanges { target: buttonBackground color: "#00000000" border.color: "#808080" } }, State { name: "down" when: comBtn.down PropertyChanges { target: buttonBackground color: "#b7b7b7" border.color: "#000000" } } ] }
Connections { target: comBtn function onPressed() { strFilePath = MyFileSelect.fnOpenDialog(); console.log("Pressed!") } }
C++:
QString MyFileSelect::fnOpenDialog() { QFileDialog fileDialog(nullptr); fileDialog.setFileMode(QFileDialog::Directory); fileDialog.setOption(QFileDialog::ShowDirsOnly, true); if ( fileDialog.exec() ) { QStringList qstrFileSavePath = fileDialog.selectedFiles(); } if ( qstrFileSavePath.isEmpty() ) { return NULL; } else { return qstrFileSavePath[0]; } }