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

Implementing the receiveReadings method

In the receiveReadings method, our goal is to transform a QByteArray containing JSON text (see Chapter 7Sending Sensor Readings to a Device with a Non-UI App, on how we encoded it) into a QVariantList of sensor readings that can be handled automatically by QML. Here is how we do it:

void channels::ReceiverBt::receiveReadings(){    qDebug() << Q_FUNC_INFO;    if (!_socket)        return;    QByteArray readingsLine = _socket->readLine();    QJsonDocument readingsDoc = QJsonDocument::fromJson(readingsLine);    QJsonArray readingsArray = readingsDoc.array();    QVariantList readings;    for (int i=0; i<readingsArray.count(); ++i) {        readings.append(readingsArray.at(i).toObject().toVariantMap());    } emit readingsProcessed(readings); ...

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