What are signals and slots?

JeffV picture JeffV · Nov 23, 2008 · Viewed 14.3k times · Source

Can someone explain in simple terms the "signals and slots" pattern?

Answer

Ferruccio picture Ferruccio · Nov 23, 2008

Signals and slots are a way of decoupling a sender (the signal) and zero or more receivers (the slots). Let's say you a system which has events that you want to make available to any other part of the system interested in those events. Rather than hard-wiring the code that generates event to the code that wants to know about those events, you would use a signals and slots pattern.

When the sender signals an event (usually by calling the function associated with that event/signal) all the receivers for that event are automatically called. This allows you to connect and disconnect receivers as necessary during the lifetime of the program.

Since this question was tagged C++, here is a link to the Boost.Signals library which has a much more thorough explanation.