Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, August 2007
Slot execuation order ?


Message 1 in thread

Hi,
 
If I have signal A which connects to two slots SLOTA and SLOTB.
Is the oder of slot execution defined when signalA is emitted ?
 
I noticed that the slot that I "connect" first to the signal is invoked
first.
Is this a rule and always gaurented to happen ?
 
R's
Prateek

Message 2 in thread

> If I have signal A which connects to two slots SLOTA and SLOTB.
> Is the oder of slot execution defined when signalA is emitted ?

If it is a DirectConnection, the Slots are called right where the emit is 
placed in your code (it's not much more than a function call). For Queued 
connections things are different. AFAIK it is not guaranteed, that slots 
are executed in any order for those. It probably depends on the Eventloop 
implementation.

Regards,
Malte

--
 [ signature omitted ] 

Message 3 in thread

> If it is a DirectConnection, the Slots are called right where the emit 
is 
> placed in your code (it's not much more than a function call). For 
Queued 
> connections things are different. AFAIK it is not guaranteed, that slots 

> are executed in any order for those. It probably depends on the 
Eventloop 
> implementation.

Forget all of above - I misunderstood your question - sorry for the noise.

Regards,
Malte

--
 [ signature omitted ] 

Message 4 in thread

Prateek Tiwari schrieb:
> Hi,
>  
> If I have signal A which connects to two slots SLOTA and SLOTB.
> Is the oder of slot execution defined when signalA is emitted ?
>  
> I noticed that the slot that I "connect" first to the signal is invoked 
> first.
> Is this a rule and always gaurented to happen ?

No. The Qt documentation explicitly states that the order is *not* 
defined in which your slots are called so you cannot rely on this behaviour:

"If several slots are connected to one signal, the slots will be 
executed one after the other, in an arbitrary order, when the signal is 
emitted." (http://doc.trolltech.com/4.3/signalsandslots.html)

Cheers, Oliver

--
 [ signature omitted ] 

Message 5 in thread

Got it.
Thank you.

R's
Prateek 

-----Original Message-----
From: Till Oliver Knoll [mailto:oliver.knoll@xxxxxxxxxxx] 
Sent: Tuesday, August 14, 2007 3:47 PM
To: Qt Interest List
Subject: Re: Slot execuation order ?

Prateek Tiwari schrieb:
> Hi,
>  
> If I have signal A which connects to two slots SLOTA and SLOTB.
> Is the oder of slot execution defined when signalA is emitted ?
>  
> I noticed that the slot that I "connect" first to the signal is 
> invoked first.
> Is this a rule and always gaurented to happen ?

No. The Qt documentation explicitly states that the order is *not*
defined in which your slots are called so you cannot rely on this
behaviour:

"If several slots are connected to one signal, the slots will be
executed one after the other, in an arbitrary order, when the signal is
emitted." (http://doc.trolltech.com/4.3/signalsandslots.html)

Cheers, Oliver

--
 [ signature omitted ]