mirror of
https://github.com/qt/qtmqtt.git
synced 2026-10-25 16:16:26 +00:00
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>
59 lines
2.0 KiB
Plaintext
59 lines
2.0 KiB
Plaintext
// Copyright (C) 2018 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
|
|
|
/*!
|
|
\example subscriptions
|
|
\title MQTT Subscriptions Example
|
|
\ingroup qtmqtt-examples
|
|
\brief Creating a application that communicates with an MQTT broker.
|
|
|
|
\image subscriptions.png
|
|
|
|
\e {MQTT Subscriptions} shows how to create an application that communicates
|
|
with an MQTT broker. A new dialog opens for each subscription, where you can
|
|
see the messages on the subscribed topics.
|
|
|
|
\section1 Creating a Client
|
|
|
|
We use the QMqttClient class to create an MQTT client and to set the broker
|
|
host name and port to use for the connection:
|
|
|
|
\quotefromfile subscriptions/mainwindow.cpp
|
|
\skipto m_client
|
|
\printuntil setPort
|
|
|
|
\section1 Subscribing to Topics
|
|
|
|
When users subscribe to topics in the client, a new subscription object is
|
|
created:
|
|
|
|
\skipto on_buttonSubscribe_clicked
|
|
\printuntil }
|
|
\printuntil }
|
|
|
|
We use the QMqttSubscription class to store the topic, state, and QoS level
|
|
of a subscription:
|
|
|
|
\quotefromfile subscriptions/subscriptionwindow.cpp
|
|
\skipto QMqttSubscription
|
|
\printuntil });
|
|
\printuntil }
|
|
|
|
The QoS level can be set separately for a message and for a subscription.
|
|
The QoS level set for a subscription determines the minimum QoS level. If
|
|
a message is sent with a higher QoS level, the broker increases the QoS of
|
|
that message to the higher level. For example, if client A subscribed to
|
|
\e topic with QoS 1, and client B publishes a message on the topic, with
|
|
QoS 0, the broker will automatically increase the QoS of the message to 1.
|
|
If client B publishes a message on the topic with the QoS 2, the broker
|
|
will send it with QoS 2.
|
|
|
|
\section2 Receiving Messages
|
|
|
|
When the client receives a message, the QMqttMessage class is used to store
|
|
the actual message payload:
|
|
|
|
\skipto updateMessage
|
|
\printuntil }
|
|
*/
|