Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
This article describes why and how to move from using Qt signals to using Boost signals.
The first paragraph contains arguments why to move from Qt signals to Boost signals and when you might refrain from it. The second paragraph and beyond follow the transition in code for two very simple classes.
My personal reasons for moving from Qt signals to Boost signals, are:
Arguments against moving from Qt signals to Boost signals are:
The program implements two classes: an emitter and a receiver. After connecting the signals and slots, the emitter emits a signal, received by the receiver.
main should be:
int main() |
Screen output should be like:
Emitter: emitting signal |
The code below would be the ideal starting point. But because moc requires the seperation of a class in a header (.h)file and implementation (.cpp) file, this code results in the link error undefined reference to 'vtable for [...]'. Due to this, next step is to seperate the class in a working example.
#include <iostream> |
The code below would be the working starting point. The next step is to replace the Qt signals by Boost signals.
#include "qtemitter.h" |
#include <iostream> |
#ifndef QTEMITTER_H |
#include <iostream> |
#ifndef QTRECEIVER_H |
In the code below, the Qt signal is replaced by using a Boost signal. The next step is: can we put all this code in a single file?
#include <iostream> |
#ifndef EMITTER_H |
#include "emitter.h" |
#include <iostream> |
#ifndef RECEIVER_H |
In the code below, all the code is placed a single file, and it works fine!
#include <iostream> |
There are reasons to move from using Qt signals to using Boost signals. This article shows that this is easy.
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.