summaryrefslogtreecommitdiffstats
path: root/examples/mqtt/doc/subscriptions.qdoc
blob: a7c17d020e1a458010a40e578c3f929f7f97de70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example subscriptions
    \examplecategory {Connectivity}
    \title MQTT Subscriptions
    \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 }
*/