From 3e04bf609afb2161efafdc4ca42656c4fdf71a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 28 Feb 2024 14:46:54 +0100 Subject: [PATCH] QMessageBox: Forward helper checkbox state via lambda There may not be a checkbox when the helper is initialized, and we want to support the case of a checkbox being added at a later stage. Regression from e5c40ec5c117376f401c01069f05780046d07094. Change-Id: I397c3b3a101b249aab17804bd90085cfd4ab7dbb Reviewed-by: Axel Spoerl (cherry picked from commit f6d09a68f6fe7100bd1c6f6039db3832a9c5dce2) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/dialogs/qmessagebox.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 2479693130a..a9506f1fc8b 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -2783,9 +2783,14 @@ void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h) auto *messageDialogHelper = static_cast(h); QObjectPrivate::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked, this, &QMessageBoxPrivate::helperClicked); + // Forward state via lambda, so that we can handle addition and removal + // of checkbox via setCheckBox() after initializing helper. QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged, - checkbox, &QCheckBox::setCheckState); - + q_ptr, [this](Qt::CheckState state) { + if (checkbox) + checkbox->setCheckState(state); + } + ); messageDialogHelper->setOptions(options); }