diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-10-22 17:58:03 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-10-24 20:30:12 +0000 |
commit | a431a6002311bcfb9ef806ae101cb27e96c26722 (patch) | |
tree | b54a9c0cfa16fc7e5fef3a555a2b4007e0650749 | |
parent | 0eff6dfe9c95514207d8af1ae0fbda5f5b13337a (diff) |
standarddialogs: Don't assume QMessageBox::exec() returns clicked role
When adding custom buttons to a QMessageBox the return value of exec()
as well as result() is not a StandardButton value, but instead an opaque
value, and the documentation says to use clickedButton() to determine
which button was clicked.
Pick-to: 6.5
Change-Id: Ib47a218989b4dcb5d51f648bc55bc02399bae602
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit 1fd1ffd03d6889273f574c698e07c611bd311fd9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/widgets/dialogs/standarddialogs/dialog.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index af8df344c7..da13b9cf41 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -454,13 +454,15 @@ void Dialog::warningMessage() tr("Delete the only copy of your movie manuscript?"), { }, this); msgBox.setInformativeText(tr("You've been working on this manuscript for 738 days now. Hang in there!")); msgBox.setDetailedText("\"A long time ago in a galaxy far, far away....\""); - msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole); - msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole); - if (msgBox.exec() == QMessageBox::AcceptRole) + auto *keepButton = msgBox.addButton(tr("&Keep"), QMessageBox::AcceptRole); + auto *deleteButton = msgBox.addButton(tr("Delete"), QMessageBox::DestructiveRole); + msgBox.exec(); + if (msgBox.clickedButton() == keepButton) warningLabel->setText(tr("Keep")); - else + else if (msgBox.clickedButton() == deleteButton) warningLabel->setText(tr("Delete")); - + else + warningLabel->setText(""); } void Dialog::errorMessage() |