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 <qt_ci_bot@qt-project.org> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
673ed80fa4
commit
2262744ad0
@ -1593,6 +1593,7 @@ void QMessageBox::showEvent(QShowEvent *e)
|
||||
}
|
||||
if (d->detailsButton)
|
||||
addButton(d->detailsButton, QMessageBox::ActionRole);
|
||||
d->clickedButton = nullptr;
|
||||
d->detectEscapeButton();
|
||||
d->updateSize();
|
||||
|
||||
|
@ -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 &,
|
||||
|
Loading…
Reference in New Issue
Block a user