blob: 42e0abdf15efa8240eb13ac820eb07da299f4e9f (
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
60
|
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example quicksubscription
\title Qt Quick Subscription
\examplecategory {Connectivity}
\ingroup qtmqtt-examples
\brief Use Qt Quick Controls to create an application that can subscribe to MQTT
topics.
\image quicksubscription.png
\e {Qt Quick Subscription} 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
Connect to QMqttSubscription::messageReceived( ) to receive all messages
sent to the broker:
\quotefromfile quicksubscription/qmlmqttclient.cpp
\skipto QmlMqttSubscription
\printuntil }
Create a \c QmlMqttClient class with the QMqttClient class as a base
class:
\skipto QmlMqttClient(
\printuntil }
Use the \c subscribe() function to create a subscription object:
\skipto subscribe
\printuntil }
Use a QMqttMessage object to store the payload of a received
message:
\skipto handleMessage
\printuntil }
\section1 Registering Classes in QML
In the \c main.cpp file, load the QML type Main from the module
subscription:
\quotefromfile quicksubscription/main.cpp
\skipto (argc
\printuntil loadFromModule
Now use the MqttClient type in the \c Main.qml file to create an
MQTT client:
\quotefromfile quicksubscription/Main.qml
\skipto MqttClient {
\printuntil }
*/
|