diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2021-09-03 18:28:00 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-05 10:36:12 +0000 |
commit | d46f5dc66157abdf55f2d746829958a9a9121343 (patch) | |
tree | 32988c0d19a0a21656db4a5e8c97cee14a37273e | |
parent | a7b3f4e3c3b4f41fa35869d76f3b942512a4d710 (diff) |
QMessageBox: Reset clickedButton for each invocation of the dialog
When showing a messagebox that has already been show we don't want to
keep around the clicked button of the previous invocation.
Change-Id: Ib6f6293d40ab338c550ea344094db871ccf45c46
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 2262744ad00524384f1ee02cdec20cf36a3b5947)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/widgets/dialogs/qmessagebox.cpp | 1 | ||||
-rw-r--r-- | tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index e1bf141079..7b6148b1d2 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1593,6 +1593,7 @@ void QMessageBox::showEvent(QShowEvent *e) } if (d->detailsButton) addButton(d->detailsButton, QMessageBox::ActionRole); + d->clickedButton = nullptr; d->detectEscapeButton(); d->updateSize(); diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 4210c428ec..b67f15458c 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -50,6 +50,7 @@ private slots: void sanityTest(); void defaultButton(); void escapeButton(); + void clickedButton(); void button(); void statics(); void about(); @@ -302,6 +303,28 @@ void tst_QMessageBox::escapeButton() QVERIFY(msgBox3.clickedButton() == msgBox3.button(QMessageBox::Ok)); // auto detected } +void tst_QMessageBox::clickedButton() +{ + QMessageBox msgBox; + msgBox.addButton(QMessageBox::Yes); + msgBox.addButton(QMessageBox::No); + msgBox.addButton(QMessageBox::Retry); + + QVERIFY(!msgBox.clickedButton()); + + for (int i = 0; i < 2; ++i) { + QAbstractButton *clickedButtonAfterExex = nullptr; + QTimer::singleShot(100, [&] { + clickedButtonAfterExex = msgBox.clickedButton(); + msgBox.close(); + }); + msgBox.exec(); + + QVERIFY(!clickedButtonAfterExex); + QVERIFY(msgBox.clickedButton()); + } +} + void tst_QMessageBox::statics() { QMessageBox::StandardButton (*statics[4])(QWidget *, const QString &, |