From 91e12dca757a8ef5c4691b70eb80db61a9d47e83 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sat, 19 Jan 2013 16:17:51 +0100 Subject: QThread documentation: do not discourage the reimplementation of QThread The new QThread documentation now really discourage to reimplement QThread. But in fact, there are many cases where it is perfectly fine. And the example given is even a case where using worker object is wrong. The examle even contains a leak since the thread will never stop and will even leak. This changes put back some sentences from before commit d4ad9dbbf96884c0899e8f8116a8a056facd52d5. The sample code has been re-writen. Notice how reimpementing run takes less lines of code, less runtime overhead, no leaks, and also is more complete than the previous example. Change-Id: I6cb80826e917dd5ce442ccad2572ec692ccb25ab Reviewed-by: Andre Somers Reviewed-by: Geir Vattekar Reviewed-by: Debao Zhang Reviewed-by: Thiago Macieira --- src/corelib/kernel/qobject.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/corelib/kernel/qobject.cpp') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index d125946781..a82242939d 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1917,7 +1917,11 @@ void QObject::removeEventFilter(QObject *obj) loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the - event loop is started. + event loop is started. If deleteLater() is called after the main event loop + has stopped, the object will not be deleted. + Since Qt 4.8, if deleteLater() is called on an object that lives in a + thread with no running event loop, the object will be destroyed when the + thread finishes. 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 -- cgit v1.2.3