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

Wiring the receiverChannel to the chart

To wire the receiverChannel to the chart, we need to:

  1. Expose the receiverChannel instance to QML
  2. Connect to the readingsPublished signal and update the chart every time the signal is emitted

The first operation is done in main.cpp with the help of QQmlContext's setContextProperty method. We already encountered this technique in Chapter 3, Wiring User Interaction and Delivering the Final App:

#include <QApplication>#include <QQmlApplicationEngine>#include <QQmlContext>#include "../channels/channel_receiver/receiver_bt.h"int main(int argc, char *argv[]){    ...    QQmlApplicationEngine engine;    engine.rootContext()->setContextProperty("receiverChannel",receiverChannel); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); ...

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