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 <axel.spoerl@qt.io>
(cherry picked from commit f6d09a68f6fe7100bd1c6f6039db3832a9c5dce2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-02-28 14:46:54 +01:00 committed by Qt Cherry-pick Bot
parent e35f20485d
commit 3e04bf609a

View File

@ -2783,9 +2783,14 @@ void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h)
auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(h); auto *messageDialogHelper = static_cast<QPlatformMessageDialogHelper *>(h);
QObjectPrivate::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked, QObjectPrivate::connect(messageDialogHelper, &QPlatformMessageDialogHelper::clicked,
this, &QMessageBoxPrivate::helperClicked); 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, QObject::connect(messageDialogHelper, &QPlatformMessageDialogHelper::checkBoxStateChanged,
checkbox, &QCheckBox::setCheckState); q_ptr, [this](Qt::CheckState state) {
if (checkbox)
checkbox->setCheckState(state);
}
);
messageDialogHelper->setOptions(options); messageDialogHelper->setOptions(options);
} }