Signals And Slots Across Threads Qt
I know this should pretty much work 'out of the box' if you pay attention to some details, which I tried to - but I must have missed something.
Now there is a way to force your code execution to jump into a slot in another thread, that is by invoking a method: QMetaObject::invokeMethod( pointerToObject., 'functionName', Qt::QueuedConnection); The Basics. So let´s go over the signal/slot mechanism quickly. There are three actors in the system: signals, slots and connect. The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments. QtScript and QML would have hardly been possible without that ability. Signals and slots are loosely coupled: A class which emits a signal neither knows nor cares which slots receive the signal. Qt's signals and slots mechanism ensures that if you connect a signal to a slot, the slot will be called with the signal's parameters at the right time. Signals and slots can take any number of arguments of any type.
I have a worker thread which starts another worker thread let's call it subworker. The worker and the subworker need to communicate via signals and slots. I make all the connections from the worker thread, and all the connect() statements return true when running (also, there's no warnings reported in the debug output).
The relevant worker thread code looks like this:
@
//! The subworker will live in its own thread
subWorkerThread = new QThread(this);
subWorkerObj.moveToThread(subWorkerThread);
//! Let it live!
subWorkerThread->start();

Qt Signal Slot Example
bool ok = connect(this, SIGNAL(work(QString)), &subWorkerObj, SLOT(beginWork(QString)));
ok = connect(&subWorkerObj, SIGNAL(signalFromSubWorker()), this, SLOT(handleSignalFromSubWorker()));
@
Then inside the subWorkerObj::beginWork:
@
emit signalFromSubWorker();
@
My debugging shows me that the beginWork() slot is correctly hit, but after the signal from SubWorker is emitted, I'm not hitting the breakpoint inside the handleSignalFromSubWorker() slot.
Signals And Slots Across Threads Qtc
Both classes subclass QObject (or a QObject subclass), both have the Q_OBJECT macro, and I made the slot in the worker public just in case.
Qt Signal Slot Performance
I'd appreciate any help, even about how to better debug it.