Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt use-case for same signal to 2 slots on same object?

Tags:

c++

qt

I am a total newbie to Qt. As I was reading the documentation, I came across this configuration:

connect( Object1, Signal1, Object2, slot1 )
connect( Object1, Signal1, Object2, slot2 )

What could possibly be the use-case for this?

Looks odd to me coming from an Erlang/Python background. It must have to do with C++ inheritance twists and turns I guess.

like image 568
jldupont Avatar asked Jan 08 '10 14:01

jldupont


2 Answers

This is for cases when you have something like one button that changes two parts of another. It may sound silly, but it would be equivalent to calling the second slot function from the first slot.

Say, clicking the play/pause button makes the stop button active or in active and also changes the tool tip. This could easily be done with one slot, but you may want the option to do them independently other times. To promote reuse, you use the above method of connecting one signal to 2 slots.

like image 179
Adam W Avatar answered Sep 22 '22 09:09

Adam W


It would allow other objects to trigger slot1 and slot2 separately.

connect( Object1, Signal1, Object2, slot1 );
connect( Object1, Signal1, Object2, slot2 );
connect( Object3, Signal1, Object2, slot1 );
connect( Object4, Signal1, Object2, slot2 );
like image 33
William Avatar answered Sep 22 '22 09:09

William