November 2018
Intermediate to advanced
1150 pages
24h 11m
English
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, ...Read now
Unlock full access