QMqttSubscription Class

The QMqttSubscription class receives notifications from an MQTT broker about a specified topic. More...

Header: #include <QMqttSubscription>
qmake: QT += mqtt
Inherits: QObject

Public Types

enum SubscriptionState { Unsubscribed, SubscriptionPending, Subscribed, UnsubscriptionPending, Error }


  • qos : const quint8
  • state : const SubscriptionState
  • topic : const QMqttTopicFilter
  • 1 property inherited from QObject

Public Functions

virtual ~QMqttSubscription() override
quint8 qos() const
QMqttSubscription::SubscriptionState state() const
QMqttTopicFilter topic() const
  • 34 public functions inherited from QObject

Public Slots

void unsubscribe()
  • 1 public slot inherited from QObject


void messageReceived(QMqttMessage msg)
void qosChanged(quint8)
void stateChanged(QMqttSubscription::SubscriptionState state)

Additional Inherited Members

  • 1 public variable inherited from QObject
  • 10 static public members inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

The QMqttSubscription class receives notifications from an MQTT broker about a specified topic.

Member Type Documentation

enum QMqttSubscription::SubscriptionState

This enum type describes the states a subscription can have.

QMqttSubscription::Unsubscribed0The topic has been unsubscribed from.
QMqttSubscription::SubscriptionPending1A request for a subscription has been sent, but is has not been confirmed by the broker yet.
QMqttSubscription::Subscribed2The subscription was successful and messages will be received.
QMqttSubscription::UnsubscriptionPending3A request to unsubscribe from a topic has been sent, but it has not been confirmed by the broker yet.
QMqttSubscription::Error4An error occured.

Property Documentation

qos : const quint8

This property holds the QoS level at which the subscription has been made.

The QoS level of the subscription specifies the maximum QoS level at which the client will receive messages. The publisher can still send messages at a lower level.

Access functions:

quint8 qos() const

Notifier signal:

void qosChanged(quint8)

state : const SubscriptionState

This property holds the state of the subscription.

Access functions:

QMqttSubscription::SubscriptionState state() const

Notifier signal:

void stateChanged(QMqttSubscription::SubscriptionState state)

topic : const QMqttTopicFilter

This property holds the topic of the subscription.

Access functions:

QMqttTopicFilter topic() const

Member Function Documentation

[override virtual] QMqttSubscription::~QMqttSubscription()

Deletes a subscription. If the topic was not already unsubscribed from, it will be unsubscribed from automatically.

[signal] void QMqttSubscription::messageReceived(QMqttMessage msg)

This signal is emitted when the new message msg has been received.

[slot] void QMqttSubscription::unsubscribe()

Unsubscribes from topic.

Note: This might affect all shared pointer instances returned by QMqttClient::subscribe().

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.