QMqttSubscription Class

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

Header: #include <QMqttSubscription>
CMake: find_package(Qt6 REQUIRED COMPONENTS Mqtt)
target_link_libraries(mytarget PRIVATE Qt6::Mqtt)
qmake: QT += mqtt
Inherits: QObject

Public Types

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

Properties

Public Functions

virtual ~QMqttSubscription() override
bool isSharedSubscription() const
quint8 qos() const
QString reason() const
QMqtt::ReasonCode reasonCode() const
QString sharedSubscriptionName() const
QMqttSubscription::SubscriptionState state() const
QMqttTopicFilter topic() const
QMqttUserProperties userProperties() const

Public Slots

void unsubscribe()

Signals

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

Detailed Description

Member Type Documentation

enum QMqttSubscription::SubscriptionState

This enum type describes the states a subscription can have.

ConstantValueDescription
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

[read-only] 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)

[read-only] reason : const QString

This property holds the reason string for the subscription.

A reason string is used by the server to provide additional information about the subscription. It is optional for the server to send it.

Access functions:

QString reason() const

[read-only] reasonCode : const QMqtt::ReasonCode

This property holds the reason code for the subscription.

The reason code specifies the error type if a subscription has failed, or the level of QoS for success.

Access functions:

QMqtt::ReasonCode reasonCode() const

[read-only] sharedSubscription : const bool

This property holds whether the subscription is shared.

Access functions:

bool isSharedSubscription() const

[read-only] sharedSubscriptionName : const QString

This property holds the name of the shared subscription.

Access functions:

QString sharedSubscriptionName() const

[read-only] state : const SubscriptionState

This property holds the state of the subscription.

Access functions:

QMqttSubscription::SubscriptionState state() const

Notifier signal:

void stateChanged(QMqttSubscription::SubscriptionState state)

[read-only] topic : const QMqttTopicFilter

This property holds the topic of the subscription.

Access functions:

QMqttTopicFilter topic() const

Member Function Documentation

[override virtual noexcept] 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().

QMqttUserProperties QMqttSubscription::userProperties() const

Returns the user properties received from the broker when the subscription has been accepted.

Note: This function will only provide valid data when the client specifies QMqttClient::MQTT_5_0 as QMqttClient::ProtocolVersion.