PDA

View Full Version : Does "emit" in the calling thread mean execution?



nomadoro
22nd September 2009, 13:08
Hello!
I've some questions regarding "emit".
(1) I've done a test and it seems to me that emitting a signal which is connected to a slot in the calling thread equals function call. Is this right?
(2) Suppose we have thread A and thread B, and now thread A is in "exec()" loop. A signal which is connected to a slot in thread A is emitted from thread B. Then how does the system treat this signal? Is the event related to the signal added to thread A's event queue and not executed until the events before it are all processed?
Thanks in advance!

Ginsengelf
22nd September 2009, 13:50
Hi, see QObject::connect, especially the ConnectionType parameter.

Ginsengelf

andy.fillebrown
22nd September 2009, 14:53
I don't know the answer to your question but when designing my thread related code, the only thing I assume is that the order of the 'emit' calls stays the same as the order they were called in when being picked up by thread A's event loop. I always just assume the other types of events could happen before or after the slot is actually called following an 'emit'. Is there some reason you need the event order to be specified, or are you just wondering? If so, then it wouldn't be hard to force the events to be called in the correct order if there was a slot-call waiting in the event queue, but that may be working against the Qt "way" and thus bad design. I'm not sure.

wysota
23rd September 2009, 12:16
(1) I've done a test and it seems to me that emitting a signal which is connected to a slot in the calling thread equals function call. Is this right?
Yes, effectively it's a function call.


(2) Suppose we have thread A and thread B, and now thread A is in "exec()" loop. A signal which is connected to a slot in thread A is emitted from thread B. Then how does the system treat this signal? Is the event related to the signal added to thread A's event queue and not executed until the events before it are all processed?

Signal is emitted as usual in thread B. The emission procedure notices it has to deliver the signal to thread A so it transforms the signal into an event and posts it into destination thread's (A's) event loop.