From 8bd70959f837c10754e4ee155b9903c6aa112c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 28 Jun 2023 15:03:11 +0200 Subject: [PATCH] QMessageBox: Set clicked button for native dialogs in clicked callback For non-native dialogs we set the clicked button before calling finalize, which emits finished(). We did the same for custom buttons in native dialogs, but for standard buttons in native dialogs we deferred it until QMessageBoxPrivate::helperDone, which meant that during the finished() signal the button was not set. We now set the button as early as possible for all three cases. Change-Id: Ifdbaa9a25105fef0bb56dd28caee9af55cd74e67 Reviewed-by: Volker Hilsheimer (cherry picked from commit cd9ae49962bbadf20c4b6599187b5a1bb0d8dc8a) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/dialogs/qmessagebox.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 9b51392901f..551663a7110 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -239,7 +239,6 @@ public: private: void initHelper(QPlatformDialogHelper *) override; void helperPrepareShow(QPlatformDialogHelper *) override; - void helperDone(QDialog::DialogCode, QPlatformDialogHelper *) override; }; void QMessageBoxPrivate::init(const QString &title, const QString &text) @@ -510,6 +509,8 @@ void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button clickedButton->click(); q->done(role); } else { + clickedButton = q->button(QMessageBox::StandardButton(button)); + Q_ASSERT(clickedButton); q->done(button); } } @@ -2837,16 +2838,6 @@ void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *) options->setCheckBox(checkbox->text(), checkbox->checkState()); } -void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *) -{ - Q_Q(QMessageBox); - QAbstractButton *button = q->button(QMessageBox::StandardButton(code)); - // If it was a custom button, a custom ID was used, so we won't get a valid pointer here. - // In that case, clickedButton has already been set in _q_buttonClicked. - if (button) - clickedButton = button; -} - void qRequireVersion(int argc, char *argv[], QAnyStringView req) { const auto required = QVersionNumber::fromString(req).normalized();