Quick MQTT Example

 // Copyright (C) 2017 The Qt Company Ltd.
 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

 #include "qmlmqttclient.h"
 #include <QDebug>

 QmlMqttClient::QmlMqttClient(QObject *parent)
     : QMqttClient(parent)
 {
 }

 QmlMqttSubscription* QmlMqttClient::subscribe(const QString &topic)
 {
     auto sub = QMqttClient::subscribe(topic, 0);
     auto result = new QmlMqttSubscription(sub, this);
     return result;
 }

 QmlMqttSubscription::QmlMqttSubscription(QMqttSubscription *s, QmlMqttClient *c)
     : sub(s)
     , client(c)
 {
     connect(sub, &QMqttSubscription::messageReceived, this, &QmlMqttSubscription::handleMessage);
     m_topic = sub->topic();
 }

 QmlMqttSubscription::~QmlMqttSubscription()
 {
 }

 void QmlMqttSubscription::handleMessage(const QMqttMessage &qmsg)
 {
     emit messageReceived(qmsg.payload());
 }