Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.15.5, 6.1.2
-
None
Description
Qt supports moving worker QObject(s) to QThread but it may be hard to find how to properly delete them in the documentation, and misguided attempts may fail silently.
The QObject::deleteLater documentation could be more explicit by complementing :
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.
With: "For instance, QThread::finished() signal can be connected to QObject::deleteLater()."
Another mention in Per-Thread Event Loop documentation would seem useful.
Finally, if some user misguidedly connect the QObject::destroyed() signal of the QThread to the wroker's QObject::deleteLater() instead, Qt could emit a warning so the user can find the actual solution. It seems like changing the following 2 comments in QCoreApplication::postEvent
// posting during destruction? just delete the event to prevent a leak
Could be complemented with a specific warning :
if (event->type() == QEvent::DeferredDelete)
qWarning("QCoreApplication::postEvent: Ignored QEvent::DeferredDelete");
The enclosed program reproduces a silent leak (confirmed with ASan) that would benefit such warning.