From 178da993a0f26d09818f8278ea72c56574f95278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Tue, 23 May 2023 08:39:22 +0200 Subject: [PATCH] QDialog - avoid potential crash In case the dialog is deleted while signals are emitted, we should likely prevent a crash. Now, obviously it would be remarkable if people deleted the dialog meanwhile, but it can also happen if the attribute WA_DeleteOnClose is set and QAppliction::processEvents() is called in a slot connected to accepted or rejected. Pick-to: 6.5 Change-Id: Iafa708dec2c1064ea890f222ff5a8d15c94cbe4c Reviewed-by: Volker Hilsheimer --- src/widgets/dialogs/qdialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index aa5e5f6d543..d0e54e013c1 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -159,13 +159,15 @@ void QDialogPrivate::close(int resultCode) void QDialogPrivate::finalize(int resultCode, int dialogCode) { Q_Q(QDialog); + QPointer guard(q); if (dialogCode == QDialog::Accepted) emit q->accepted(); else if (dialogCode == QDialog::Rejected) emit q->rejected(); - emit q->finished(resultCode); + if (guard) + emit q->finished(resultCode); } QWindow *QDialogPrivate::transientParentWindow() const