Revision control
- /****************************************************************************
- **
- ** Copyright (C) 2018 The Qt Company Ltd.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the documentation of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:FDL$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU Free Documentation License Usage
- ** Alternatively, this file may be used under the terms of the GNU Free
- ** Documentation License version 1.3 as published by the Free Software
- ** Foundation and appearing in the file included in the packaging of
- ** this file. Please review the following information to ensure
- ** the GNU Free Documentation License version 1.3 requirements
- ** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+ // Copyright (C) 2018 The Qt Company Ltd.
+ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example simpleclient
\title Simple MQTT Client Example
\ingroup qtmqtt-examples
\brief Creating a minimalistic telemetry application.
\image simpleclient.png
\e {Simple MQTT Client} demonstrates how to create a minimalistic client
application.
To use the application, you first specify a broker, such as
\e test.mosquitto.org or \e broker.hivemq.com and the port number 1883, and
connect to it. You can then subscribe to a topic and send a message, which
you will also receive.
\note Port number 1883 is not encrypted, and therefore it is suitable only
for development and testing purposes. In production, always use encrypted
connections.
\section1 Creating a Client
First, we use the QMqttClient class to create an MQTT client. The class
provides properties for setting a unique client ID as well as the broker
host name and port to connect to:
\quotefromfile simpleclient/mainwindow.cpp
\skipto m_client
\printuntil setPort
We do not set the client ID, and therefore it will be automatically
generated for us.
Next, we connect to QMqttClient::messageReceived() to receive all messages
sent to the broker:
\skipto messageReceived
\printuntil }
When users subscribe to topics in the client, we call
QMqttClient::subscribe() on the specified topic:
\skipto on_buttonSubscribe_clicked
\printuntil }
In this example, we subscribe to all topics. For more information about
how to receive messages on particular topics, see
\l {MQTT Subscriptions Example}.
For an example of how to use the QMqttClient class in a Qt Quick
application, see \l {Quick MQTT Example}.
*/