- Signals and slots
Signals and slots is a language construct introduced in Qt, which makes it easy to implement the
Observer pattern while avoiding boilerplate code. The concept is that controls (also known as widgets) can send signals containing event information (e.g. the text "toto" was selected, the scrollbar has been adjusted to value 37) which can be received by other controls using special functions known as slots. The signal/slot system fits well with the wayGraphical User Interface s are designed. Similarly, the signal/slot system can be used forasynchronous I/O (including sockets, pipes, serial devices, etc.) event notification or to associate timeout events with appropriate object instances and methods or functions. A signal to slot connection is the equivalent of the Design Pattern Observer. No registration/deregistration/invocation code must be written, because Qt's Meta Object Compiler (MOC) automatically generates the needed infrastructure.There are some implementations of signal/slot systems based on
C++ templates, which don't require the extra Meta Object Compiler, as used by Qt, such aslibsigc++ , [http://sigslot.sourceforge.net/ sigslot] , and [http://www.boost.org/doc/html/signals.html boost.signals] . The C# language also supports a similar construct although with a different terminology and syntax: events play the role of signals, and delegates are the slots. Additionally, a delegate can be a local variable, much like afunction pointer , while a slot in Qt must be a class member declared as such.See also
*
Observer pattern
*Signal programming
*Delegate (.NET) References
* [http://doc.trolltech.com/4.4/signalsandslots.html Signals and slots] , from Qt documentation.
Wikimedia Foundation. 2010.