diff options
author | Dheerendra Purohit <[email protected]> | 2025-07-05 12:47:39 +0530 |
---|---|---|
committer | Dheerendra Purohit <[email protected]> | 2025-07-12 18:30:13 +0530 |
commit | 50f1288946cae0ad8a66d5003fc4bb8138d9b6dd (patch) | |
tree | b706527e2c8248fb75118d0a5a90c687d9b66fd0 /src/corelib/kernel/qobject.cpp | |
parent | ff5351b12f4dd6de1a96728859456aac556272af (diff) |
Add example of QThread::finished or deleteLater in QObject
docs.
Pick-to: 6.10 6.9 6.8
Fixes: QTBUG-94939
Change-Id: I385aef86f88a4bb92d3d647468bbbe94225010e2
Reviewed-by: Thiago Macieira <[email protected]>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index d67ada64c45..790ccc29339 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2520,6 +2520,14 @@ void QObject::removeEventFilter(QObject *obj) thread with no running event loop, the object will be destroyed when the thread finishes. + A common pattern when using a worker \c QObject in a \c QThread + is to connect the thread's \c finished() signal to the worker's + \c deleteLater() slot to ensure it is safely deleted: + + \code + connect(thread, &QThread::finished, worker, &QObject::deleteLater); + \endcode + Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will \e not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() |