diff options
author | Thorbjørn Lund Martsum <tmartsum@gmail.com> | 2023-05-23 08:39:22 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-05-24 11:08:35 +0000 |
commit | 178da993a0f26d09818f8278ea72c56574f95278 (patch) | |
tree | 852269a9f33457378c607bb4b590800c1b4d96bb /src/widgets | |
parent | c891d16490b6b5bd2f912c49356b8292d4c3fb42 (diff) |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/dialogs/qdialog.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index aa5e5f6d54..d0e54e013c 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<QDialog> 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 |