bhupinder
bhupinder

Reputation: 335

connecting one signal to two slots of same thread

I want to connect one signal to my two slots of same thread in qt. Is it possible.

    connect (closL[0], SIGNAL(clicked()),signalMapperL, SLOT(map())) ;
signalMapperL -> setMapping (closL[0], PIDL) ;
connect (signalMapperL, SIGNAL(mapped(int)), this, SLOT(ResumeMic(int))) ;

connect (closL[0], SIGNAL(clicked()),signalMapperL, SLOT(map())) ;
signalMapperL -> setMapping (closL[0], PIDL) ;
connect (signalMapperL, SIGNAL(mapped(int)), this, SLOT(closeAppL(int))) ;

I want to give pause/resume option on single same button in my app

thanku

Upvotes: 2

Views: 920

Answers (1)

Max
Max

Reputation: 121

I'm not sure about the purpose of you signal mapper here, however...

You can make as many connections to a signal as you like.

The connected slots will be called in same order as connected. If you connect the same slot multiple times, it will be called multiple times unless you specify Qt::UniqueConnection as parameter to connect.

If the slot is connected directly (default when sender and receiver live in the same thread) the slots are called synchronously when the signal is emitted.

If the slot is triggered on a QObject living in a different thread, the call will not be made directly but using the event loop (=> queued connection). You can force queued connections also for QObjects living in the same thread which is sometimes necessary to avoid slot fire sequence problems by passing Qt::QueuedConnection to connect.

Hopefully this answers you question.

Upvotes: 3

Related Questions