Citation:
Signals and slots are a refinement of the Observer Pattern, a powerful
metaphor, and a great tool for assembling software from components.
They've been a part of the computer science landscape for over a
decade, and many mature implementations exist.
The implementation in Qt is a fundamental part of Qt's architechture,
and tightly integrated with its widgets, threading, introspection,
scripting, meta-object machinery, and visual GUI layout tool, Qt
Designer. Qt signals are member function signatures that can only be
emitted by the object of which they are members. Qt slots are specially
designated member functions. Qt widgets and connections can be
described in non-code resources and instantiated from such resources at
runtime. Qt signals and slots are built upon the introspection facility of
meta-objects in Qt, which is made possible by moc, the meta-object
compiler that produces meta-object classes matching user-defined
classes that specifically request this by mentioning Q_OBJECT in their
declaration.
Boost.Signals is a statically type-safe, template-based implementation of
signals and slots, where signals are instances of the template boost::signal
and slots are any callable signature. Boost.Signals stands alone, and
does not require introspection, meta-objects, or external tools; but the
downside of this is that Boost.Signals does not include a facility to
describe connections in non-code resources.
These two implementations both have great and complementary
strengths. Using them together until now has been a challenge. In Qt 4.1
and beyond, it's easy to use both if that happens to be right for your
project.
Any Qt-based project with a GUI will naturally use signals and slots. You
can also benefit from signals and slots in simulations and many
environments where software components can be assembled with loose
couplings into a larger system. As with any metaphor or technique,
moderation is the key. Choose wisely where to use signals and slots and
you will be rewarded with a system that's easier to understand, more
flexible, highly re-usable, and working sooner.