21 #include <QAbstractEventDispatcher> 22 #include <QMetaObject> 32 template <
typename Function>
33 void postToObject(QObject *
object, Function &&
function)
37 QMetaObject::invokeMethod(
38 object, std::forward<Function>(
function), Qt::QueuedConnection);
41 template <
typename Function>
42 void postToThread(QThread * pThread, Function &&
function)
45 Q_ASSERT(!pThread->isFinished());
47 QObject * pObject = QAbstractEventDispatcher::instance(pThread);
52 auto pDummyObj = std::make_unique<QObject>();
53 pDummyObj->moveToThread(pThread);
56 [pObj = pDummyObj.get(),
57 function = std::forward<Function>(
function)]()
mutable {
61 Q_UNUSED(pDummyObj.release())
65 if (pThread == QThread::currentThread()) {
71 QMetaObject::invokeMethod(pObject, std::forward<Function>(
function));
Definition: threading/Factory.h:24