[Qt-interest] QThread Question
Sean Harmer
sean.harmer at maps-technology.com
Thu Aug 6 13:29:46 CEST 2009
Hi Donal,
On Thursday 06 Aug 2009 12:10:57 Donal O'Connor wrote:
> Ok I see but actually looking at the code, there are some instance's where
> it is just a regular method and not a slot. Does this mean, when the method
> is called, that it is run in the calling thread?
Yes, as there is no mechanism to switch it over to the other thread in this
case. It is just a direct call. The same applies even if the function is a
slot but is called directly.
Queued connections hand the call over to the worker thread by posting to the
worker thread's event queue. This event is interpreted by the thread's exec()
function which then calls the appropriate slot with the correct arguments.
This is why you must enter the event loop (by calling exec()) in order to get
signals/slots working across thread boundaries.
> Plus, no where have specified the connection type to be Queued, I'm
> assuming direct connection is the default and this results in the slot
> being called in the calling thread?
If the thread has been moved to itself, then this is not strictly necessary as
connect() figures this out for you. However, when dealing with threads I find
it useful to be explicit to minimise confusion/ambiguity.
> Bit of a mess the code here!
Good luck!
Sean
More information about the Qt-interest-old
mailing list