-
Suggestion
-
Resolution: Fixed
-
Not Evaluated
-
5.15.5, 6.1.2
-
None
-
-
50f128894 (dev), 97e9961e6 (6.10), 6db9ac705 (6.9), 87d03808d (tqtc/lts-6.8)
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.
For Gerrit Dashboard: QTBUG-94939 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
658945,1 | Doc: Clarify correct usage of deleteLater in threads.qdoc | dev | qt/qtdoc | Status: NEW | -1 | 0 |