blob: 85dbb7d12ea662548d7bf0aff3bae16df6752126 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "queuedinvoker.h"
#include <QMetaObject>
#include <QThread>
#include <QDebug>
#include <QMutexLocker>
QueuedInvoker::QueuedInvoker()
{
connect(this, SIGNAL(queuedCall(const char *)),
this, SLOT(onQueuedCall(const char *)),
Qt::QueuedConnection);
}
void QueuedInvoker::onQueuedCall(const char *method)
{
QMutexLocker locker(&callQueueLock);
callQueue.remove(method);
qDebug() << "Hope that i'm in the main loop" << QThread::currentThread();
locker.unlock();
if (!QMetaObject::invokeMethod(this, method, Qt::DirectConnection)) {
qFatal(" *****************\n"
"Erroneous usage of queueOnce(%s)\n"
" *****************\n", method);
}
}
void QueuedInvoker::queueOnce(const char *method)
{
QMutexLocker locker(&callQueueLock);
if (!callQueue.contains(method)) {
emit queuedCall(method);
callQueue.insert(method);
}
}
|