1
0
mirror of https://github.com/qt/qtmqtt.git synced 2026-10-25 16:16:26 +00:00
qtmqtt/examples/mqtt/doc/quicksubscription.qdoc
Lucie Gérard edd6855344 Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: Ie4309963c8e17d4e7dad602f61a660246d5e23cb
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-06-16 10:22:20 +02:00

64 lines
1.7 KiB
Plaintext

// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example quicksubscription
\title Quick MQTT Example
\ingroup qtmqtt-examples
\brief Registering QMqttClient to QML and using it in a Qt Quick user
interface.
\image quicksubscription.png
\e {Quick MQTT} demonstrates how to register QMqttClient as a QML type and
use it in a Qt Quick application.
\l {Qt MQTT} does not provide a QML API in its current version. However,
you can make the C++ classes of the module available to QML.
\section1 Creating a Client
We create a \c QmlMqttClient class with the QMqttClient class as a base
class:
\quotefromfile quicksubscription/qmlmqttclient.cpp
\skipto QmlMqttClient(
\printuntil }
We use the \c subscribe() function to create a subscription object:
\printuntil }
We connect to QMqttSubscription::messageReceived( ) to receive all messages
sent to the broker:
\printuntil }
We use an QMqttMessage object to store the payload of a received
message:
\skipto handleMessage
\printuntil }
\section1 Registering Classes in QML
In the \c main.cpp file, we register the \c QmlMqttClient class as a
QML type, MqttClient:
\quotefromfile quicksubscription/main.cpp
\skipto main(int
\printuntil qmlRegisterType
In addition, we register the \c QmlMqttSubscription class as an uncreatable
type:
\printuntil qmlRegisterUncreatableType
We can now use the MqttClient type in the \c main.qml file to create an
MQTT client:
\quotefromfile quicksubscription/main.qml
\skipto MqttClient {
\printuntil }
*/