2

I'm just trying to figure out what makes the Signal/Slot (Pattern?). Wikipedia tells me not so much and calls it an implementation of the ObserverPattern* while I would think it has much more resemblance to the DataBusPattern**.

Can someone explain in an abstract way what Signal/Slot is? Do the participants in Signal/Slot need to know each other (as in ObserverPattern) or not (as in DataBusPattern) and what are the key differences?

I tried to figure it out reading the QT docs, but there is to much C++ magic.

*) http://c2.com/cgi/wiki?ObserverPattern

**) http://c2.com/cgi/wiki?DataBusPattern

1
  • Signal/Slot is mostly an improvement to the callback mechanism, while DataBus/EventBus always includes a thread/process model.
    – Brent81
    Feb 23 '20 at 1:42
4

The connection information between a signal and a slot is completely held between the connected sender and receiver objects. See here for more information. A connect operation is always given between two concrete instances, and the programmer must know about both of them. One is doing the publishing, one is doing the subscribing. You can connect many signals to one slot, and many slots to one signal, but each connection is made individually.

In a data bus pattern, you don't make individual connections. You just broadcast your events onto the bus, and every receiver on the bus receives every single event. They can choose not to do anything with certain events, but they can't choose not to receive them at all.

2
  • Thanks for your answer! It seems I completely misunderstood Signal/Slot. But know: What's the difference to ObserverPattern (e.g. like in Events/Listeners) then? Or is it that just another name because QT has it in every QObject? (Sorry, I stopped reading your Link at "The Meta Object Compiler" where too much C++ happend...)
    – Scheintod
    Dec 12 '14 at 17:10
  • It is the observer pattern. A signal is an event and a slot is a listener. The meta object compiler just takes care of the boilerplate of implementing the pattern for you. Dec 12 '14 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.