mirror of
https://github.com/qt/qtmqtt.git
synced 2026-10-25 16:16:26 +00:00
Alternate text (alt text) improves the documentation experience for
screen readers and for other accessibility tools.
Task-number: QTBUG-135098
Change-Id: Ia1793ff3e0bacd8cfdad2e8c04725a5093ed30aa
Reviewed-by: David Boddie <david.boddie@qt.io>
(cherry picked from commit 34656ac5ba)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
63 lines
1.8 KiB
Plaintext
63 lines
1.8 KiB
Plaintext
// Copyright (C) 2023 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
|
|
|
|
/*!
|
|
\example quickpublication
|
|
\title Qt Quick Publication
|
|
\examplecategory {Connectivity}
|
|
\ingroup qtmqtt-examples
|
|
\brief Use Qt Quick Controls to create an application that can publish on MQTT
|
|
topics.
|
|
|
|
\image quickpublication.png
|
|
{MQTT publishing interface with Hostname, Port, Topic, Message, QoS,
|
|
and Retain fields}
|
|
|
|
\e {Qt Quick Publication} 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
|
|
|
|
Create the wrapper class \c QmlMqttClient that has QMqttClient as a member:
|
|
\quotefromfile quickpublication/qmlmqttclient.h
|
|
\skipto private
|
|
\printuntil }
|
|
|
|
Connect the wrapper methods to the methods of QMqttClient in the constructor:
|
|
\quotefromfile quickpublication/qmlmqttclient.cpp
|
|
\skipto QmlMqttClient
|
|
\printuntil }
|
|
|
|
A wrapper method has the same name as the wrapped method. In the simplest case,
|
|
it is just a single method call:
|
|
|
|
\skipto connectToHost
|
|
\printuntil }
|
|
|
|
It is also possible to customize a wrapper method by extending it with some additional
|
|
functionality:
|
|
|
|
\skipto setPort
|
|
\printuntil );
|
|
|
|
\section1 Registering Classes in QML
|
|
|
|
In the \c main.cpp file, load the QML type Main from the module
|
|
publication:
|
|
|
|
\quotefromfile quickpublication/main.cpp
|
|
\skipto (argc
|
|
\printuntil loadFromModule
|
|
|
|
|
|
Now use the MqttClient type in the \c Main.qml file to create an
|
|
MQTT client:
|
|
|
|
\quotefromfile quickpublication/Main.qml
|
|
\skipto MqttClient {
|
|
\printuntil }
|
|
*/
|