Details
-
Bug
-
Resolution: Done
-
P4: Low
-
4.8.x, 5.12.0
-
None
-
-
c41c5159d7d7688d61bdd1b013278302bb0116fb (qt/qtbase/5.12)
Description
While asking myself how to invoke meta object slots from non qt managed threads, I stumbled over the very common seen pattern, to use QMetaObject::invokeMethod with Qt::QueuedConnection , also on this bug tracker, see QTBUG-70915 .
However, in contrast to QCoreApplication::postEvent, QMetaObject::invokeMethod has no statement about thread safety (nor reentrancy, but this can be assumed for almost all QtMethods). So either this pattern is causing UB around the world, or QMetaObject::invokeMethod should IMHO document its thread safety guarantees. And I don't only mean the constraint that the caller should make sure that the recipient stays alive until after the invocation, but more important the contract that this method would use the Qt globals in a thread unsafe matter)
(Forum thread https://forum.qt.io/topic/97683/thread-safety-of-qmetaobject-invokemethod-e-g-slot-invoking-from-random-threads )