Consider a QObject
:
class TestObject: public QObject
{
Q_OBJECT
public slots:
void doStuff();
};
We will run this object in some different thread:
TestObject* o = new TestObject;
o->moveToThread(someThreadPointer);
Now, how do I invoke doStuff
so that it happens in the worker thread? If I have other object in main thread, I can do this:
class OtherObject: public QObject
{
Q_OBJECT
signals:
signalToDoStuff();
};
In main thread then:
TestObject* o = new TestObject;
o->moveToThread(someThreadPointer);
OtherObject other* = new OtherObject;
QObject::connect(other, &OtherObject::signalToDoStuff, o, &TestObject::doStuff);
// Emit the signal which causes `doStuff` to be called in other thread
other->signalToDoStuff();
But that's a long way around. I need to queue up an event for doStuff
to be called.