summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-22 17:58:03 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-24 22:30:03 +0200
commit1fd1ffd03d6889273f574c698e07c611bd311fd9 (patch)
tree9486fc2325a270db989f045998d400556a6a7d5c
parent13fbedd162d167bb3cdbf95181b0870f61cf2ce0 (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.6 6.5 Change-Id: Ib47a218989b4dcb5d51f648bc55bc02399bae602 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index e46c337888..67fb615794 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -455,13 +455,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()