21#include <QAbstractEventDispatcher>
30namespace quentier::threading {
32template <
typename Function>
33void postToObject(QObject *
object, Function && function)
37 QMetaObject::invokeMethod(
38 object, std::forward<Function>(function), Qt::QueuedConnection);
41template <
typename Function>
42void 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));