Tweak QObject::deleteLater() documentation a bit

The Qt 4.8 reference is not relevant. And mentioning that calling the
function more than once is safe, or why that is, is strange, as users
should still treat the object as something that will go away soon.

Change-Id: Icf24aa8ffe079e35351006dd77063df48a596fab
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit e02dc31fbf3ae460bea2aea068ccc969d6e852fc)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-12-15 12:05:55 +01:00
parent f83ba9d3cf
commit c69ad0a66e

View File

@ -2416,9 +2416,20 @@ void QObject::removeEventFilter(QObject *obj)
event loop was still running: the Qt event loop will delete those objects
as soon as the new nested event loop starts.
\note It is safe to call this function more than once; when the
first deferred deletion event is delivered, any pending events for the
object are removed from the event queue.
In situations where Qt is not driving the event dispatcher via e.g.
QCoreApplication::exec() or QEventLoop::exec(), deferred deletes
will not be processed automatically. To ensure deferred deletion in
this scenario, the following workaround can be used:
\code
const auto *eventDispatcher = QThread::currentThread()->eventDispatcher();
QObject::connect(eventDispatcher, &QAbstractEventDispatcher::aboutToBlock,
QThread::currentThread(), []{
if (QThread::currentThread()->loopLevel() == 0)
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
);
\endcode
\sa destroyed(), QPointer
*/