Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72599

QMetaObject::invokeMethod thread safety unclear

XMLWordPrintable

    • All
    • c41c5159d7d7688d61bdd1b013278302bb0116fb (qt/qtbase/5.12)

      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 )

        For Gerrit Dashboard: QTBUG-72599
        # Subject Branch Project Status CR V

            thiago Thiago Macieira
            superlokkus Markus Klemm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes