From 2262744ad00524384f1ee02cdec20cf36a3b5947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 3 Sep 2021 18:28:00 +0200 Subject: 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. Pick-to: 6.2 Change-Id: Ib6f6293d40ab338c550ea344094db871ccf45c46 Reviewed-by: Qt CI Bot Reviewed-by: Timur Pocheptsov --- .../dialogs/qmessagebox/tst_qmessagebox.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp') 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 &, -- cgit v1.2.3