From 23d7faa8a1f69a97d8e094be7e81f907361b02ae Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 5 Mar 2024 14:32:45 +0100 Subject: [PATCH] QObject: fix a documentation note in the destructor The docs for ~QObject say: > any pending posted events for the object are removed from the event > queue but then they also say: > Deleting a QObject while pending events are waiting to be delivered > can cause a crash These two contradict each other. In fact, the first one is correct, the second one is factually incorrect. Amend it to what I believe it's the intended meaning: do not destroy a QObject which is _handling_ an event (i.e. we're into QObject::event() or an override). Change-Id: Id1d564f296e17a764e0f49ebfedf6e292085c221 Pick-to: 6.6 6.5 6.2 Reviewed-by: Thiago Macieira Reviewed-by: Shantanu Tushar Reviewed-by: Fabian Kosmale (cherry picked from commit 6e0c438a41a61a3d0a93954f00f46951c4399224) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qobject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 54bbe3085a3..92f0944ba78 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1023,8 +1023,8 @@ void QObjectPrivate::clearBindingStorage() outside the parent. If you still do, the destroyed() signal gives you an opportunity to detect when an object is destroyed. - \warning Deleting a QObject while pending events are waiting to - be delivered can cause a crash. You must not delete the QObject + \warning Deleting a QObject while it is handling an event + delivered to it can cause a crash. You must not delete the QObject directly if it exists in a different thread than the one currently executing. Use deleteLater() instead, which will cause the event loop to delete the object after all pending events have been