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

Qt-interest Archive, May 2007
Basic question in Signals and Slots


Message 1 in thread

Hi,

A basic question in QT ....

I have connected signal1 to slot1, signal2 to slot2, signal3 to slot3 and 
signal4 to slot4.

signal1 is emitted and so slot1 is executed.

Within the slot1, I am emitting the other three signals.

slot1()
{
        //do some stuff
        emit signal2;

        //do some stuff
        emit signal3;

        //do some stuff
        emit signal4;
 
}

And the other slots are doing some simple stuff.

My Question is how the slots are executed. I have run  a sample with just 
print statements.

The control flow is ---> slot1() and in slot1 , after emitting the signal2 
..... it is completing the stuff in slot2 and then the control comes to 
next statement after emit signal2, then emits signal3 complets slot3 , 
emits signal4 complets slot4.

But I expect the slot1() will continue its execution after emitting 
signal2 without waiting for slot2 to be completed.

Where I am gone wrong?

Thanks & Regards,
Hemanth Kumar Nakkina
Tata Consultancy Services
Mailto: hemanth.n@xxxxxxx
Website: http://www.tcs.com
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Message 2 in thread

Have a look at the docs:

http://doc.trolltech.com/4.2/signalsandslots.html

In most cases, a signal results in the corresponding slots to be called
immediatly. Don't mix them up with events!

Cheers,
Peter

> But I expect the slot1() will continue its execution after emitting
> signal2 without waiting for slot2 to be completed.
> 
> Where I am gone wrong?

--
 [ signature omitted ] 

Message 3 in thread

On 5/9/07, Hemanth N <hemanth.n@xxxxxxx> wrote:

> But I expect the slot1() will continue its execution after emitting signal2
> without waiting for slot2 to be completed.
>
> Where I am gone wrong?

That is because the connected slots are direct connected which means
execution will continue into those slots before returning to your
emit.

By using QueuedConnection on your slots, the signal is queued inside
Qt and emitted when control is back at Qt mainloop.

-- 
 [ signature omitted ]