PDA

View Full Version : Differences in calling a Slot



Denarius
28th April 2009, 12:50
Hello,

Is there a difference when you call a Slot?
I connect a signal to a slot, the signal is handled when the object has time for it.

I call the slot directly by: slotName();

Is there a difference in the way the slot is being handled?
Or is the slot handled in the same way as if it is called by a signal?

wysota
28th April 2009, 13:07
If you are using a single thread then there is practically no difference.

Denarius
28th April 2009, 13:54
But what about threaded?

jpn
28th April 2009, 14:09
See the explanation in Qt::QueuedConnection. Notice that the receiving thread must be running an event loop.

Ginsengelf
28th April 2009, 14:10
It depends on the last parameter in connect(): see Connection type (http://doc.trolltech.com/4.3/qt.html#ConnectionType-enum).

Ginsengelf

Denarius
28th April 2009, 14:36
I know how the connect function works :P

The question was:
Is there any difference when calling the slot directly? (So I do NOT use a signal or a connect)

Example:


void myClass::MyFunction()
{
if(something_happens)
callAthreadsSlot(); //NO EMIT JUST CALL IT
}

jpn
28th April 2009, 14:58
Slots are normal functions in the sense that the meta-object compiler just generates some additional meta-data to be able to call slots dynamically by name at runtime. If you call a slot like a normal function, the function gets executed in the calling thread context. If you use signals and slots, the signal would get automatically queued by default if the sender and receiver live in different threads.

Denarius
28th April 2009, 15:32
Slots are normal functions in the sense that the meta-object compiler just generates some additional meta-data to be able to call slots dynamically by name at runtime. If you call a slot like a normal function, the function gets executed in the calling thread context. If you use signals and slots, the signal would get automatically queued by default if the sender and receiver live in different threads.

Thank you. This was the answer I was looking for.