I am a total newbie to Qt. As I was reading the documentation, I came across this configuration:
connect( Object开发者_JAVA技巧1, 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.
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.
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 );
It's actually a really powerful way of doing MVC... Let's say you want to "connect" views to listen to an object than emit datas...
You can connect a PieChart view with :
connect( MySourceModel, SIGNAL(newDataAreThere()), PieChartView, SLOT(notifyNewDataReceived()));
Later in your application, another module is created and need as well to listen to data... No problem :
connect( MySourceModel, SIGNAL(newDataAreThere()), AnotherView, SLOT(notifyNewDataReceived()));
You can connect/disconnect your views, and the model doesn't even know who are listening to him... That's not his problem...
I hope my little example is understandable ;)
精彩评论