O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Having the broadcaster emit readings at regular intervals

In the previous chapter, in cmbroadcast's main.cpp, we only called Sensor::emitReading once. Since we now need a time series to be displayed on the chart, we are going to improve on that. We will be emitting a reading every second by using a QTimer instance, and have the emitted values follow a sinusoidal shape as a function of time by means of the qSin macro. Furthermore, we will start this regular broadcasting as soon as a receiver connects to the broadcaster. Here is how:

// cmbroadcast/main.cpp...#include <QtMath>int main(int argc, char *argv[]){    QCoreApplication app(argc, argv);    ...    QTimer sensorTimer;    sensorTimer.setInterval(1000); QObject::connect(&sensorTimer, &QTimer::timeout, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required