Suppose I have a background thread that at some point emits a signal from an object (the object belongs to the GUI thread!):
qDebug() << "before signal emitted";
emit mySignal();
qDebug() << "after signal emitted";
qDebug() << "before signal emitted";
emit mySignal();
qDebug() << "after signal emitted";
To copy to clipboard, switch view to plain text mode
This signal is connected to a slot on another object from the GUI thread:
void QMyObject::mySlot() {
qDebug() << "signal received";
}
void QMyObject::mySlot() {
qDebug() << "signal received";
}
To copy to clipboard, switch view to plain text mode
In the debug output I see the following order of messages:
before signal emitted
after signal emitted
signal received
before signal emitted
after signal emitted
signal received
To copy to clipboard, switch view to plain text mode
Which makes me think that when the signal is emitted, it does not wait for the slots. Although the documentation states the opposite:
Execution of the code following the
emit statement will occur once all slots have returned
Basically in my case I would want the emitting side to wait for all the slots to process the signal. The behavior I observe is probably due to cross-thread execution, but it should be uniform for all cases, shouldn't it?
Thanks
Anton
Bookmarks