Boost Signal Slot Vs Qt

Each PyQt widget, which is derived from QObject class, is designed to emit ‘signal’ in response to one or more events. The signal on its own does not perform any action. Instead, it is ‘connected’ to a ‘slot’. The slot can be any callable Python function. In PyQt, connection between a signal and a slot can be achieved in different ways.

  • Compiling a rqtguicpp plugin which (transitively) depends on boost signals (e.g. Via tf package) fails to compile due to macro name clashes of Qt's 'signals', 'slots', 'emit' macros as described here.
  • Why I dislike Qt signals/slots (Originally posted on Sunday, February 19th, 2012.) I've created over a dozen small projects using Qt by now. Most of the time I think I might as well make use of Qt's signals/slots system - I mean it's already there.

Signals and slots is a language construct introduced in Qt for communication between objects[1] which makes it easy to implement the observer pattern while avoiding boilerplate code. The concept is that GUI widgets can send signals containing event information which can be received by other widgets / controls using special functions known as slots. This is similar to C/C++ function pointers, but signal/slot system ensures the type-correctness of callback arguments.[citation needed]

The signal/slot system fits well with the way graphical user interfaces are designed. Similarly, the signal/slot system can be used for other non-GUI usages, for example asynchronous I/O (including sockets, pipes, serial devices, etc.) event notification or to associate timeout events with appropriate object instances and methods or functions. It is easy to use and no registration/deregistration/invocation code need to be written, because Qt's metaobject compiler (MOC) automatically generates the needed infrastructure.

A commonly used metaphor is a spreadsheet. A spreadsheet has cells that observe the source cell(s). When the source cell is changed, the dependent cells are updated from the event.

Alternative implementations[edit]

There are some implementations of signal/slot systems based on C++ templates, which don't require the extra metaobject compiler, as used by Qt, such as libsigc++, sigslot, vdk-signals, nano-signal-slot, neosigslot, Signals, boost.signals2, Synapse, Cpp::Events, Platinum and JBroadcaster. Common Language Infrastructure (CLI) languages such as C# also supports a similar construct although with a different terminology and syntax: events play the role of signals, and delegates are the slots. Another implementation of signals exists for ActionScript 3.0, inspired by C# events and signals/slots in Qt. Additionally, a delegate can be a local variable, much like a function pointer, while a slot in Qt must be a class member declared as such. The C based GObject system also provides similar functionality via GSignal.In D it is implemented by std.signals.

See also[edit]

Libraries[edit]

Java: sig4j - multi-threaded, type-safe, based on the FunctionalInterface annotation introduced in Java 8.

C++: vdk-signals - thread-safe, type-safe, written in C++11 with atomic variables.

References[edit]

  1. ^'Signals & Slots - QtCore 5.1'. Qt Project. 2013-07-04. Retrieved 2013-07-04.
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Signals_and_slots&oldid=839724350'

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign up New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milestone

Qt Signal Slot Connect

Comments

Signal

commented Jun 16, 2015

Boost Signal Slot Vs Qt 3

Compiling a rqt_gui_cpp plugin which (transitively) depends on boost signals (e.g. via tf package) fails to compile due to macro name clashes of Qt's 'signals', 'slots', 'emit' macros as described here:
http://wiki.ros.org/qt_ros/Tutorials/Mixing%20Qt%20and%20Boost%20Signals

For such a plugin to compile the QT_NO_KEYWORDS flag can be set in its cmake file:
ADD_DEFINITIONS(-DQT_NO_KEYWORDS)

But this breaks the current code of qt_gui_core at:
https://github.com/ros-visualization/qt_gui_core/blob/fuerte-devel/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.h#L63

And also a few other files in the rqt package are affected:
https://github.com/ros-visualization/rqt/search?l=cpp&q=signals+OR+slots+OR+emit&type=Code&utf8=%E2%9C%93

Changing the keywords as follows would resolve this issue:

  • signals -> Q_SIGNALS
  • slots -> Q_SLOTS
  • emit -> Q_EMIT
  • foreach -> Q_FOREACH

The use of the QT_NO_KEYWORDS flag should also be mentioned in the rqt cpp plugin tutorial.

Signals And Slots Qt

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment