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 |
enum | SubscriptionState { Unsubscribed, SubscriptionPending, Subscribed, UnsubscriptionPending, Error } |
|
|
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 |
void | unsubscribe() |
void | messageReceived(QMqttMessage msg) |
void | qosChanged(quint8) |
void | stateChanged(QMqttSubscription::SubscriptionState state) |
This enum type describes the states a subscription can have.
Constant | Value | Description |
---|---|---|
QMqttSubscription::Unsubscribed |
0 |
The topic has been unsubscribed from. |
QMqttSubscription::SubscriptionPending |
1 |
A request for a subscription has been sent, but is has not been confirmed by the broker yet. |
QMqttSubscription::Subscribed |
2 |
The subscription was successful and messages will be received. |
QMqttSubscription::UnsubscriptionPending |
3 |
A request to unsubscribe from a topic has been sent, but it has not been confirmed by the broker yet. |
QMqttSubscription::Error |
4 |
An error occured. |
[read-only]
qos : const quint8This 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, since 5.12]
reason : const QStringThis 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.
This property was introduced in Qt 5.12.
Access functions:
QString | reason() const |
[read-only, since 5.12]
reasonCode : const QMqtt::ReasonCodeThis 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.
This property was introduced in Qt 5.12.
Access functions:
QMqtt::ReasonCode | reasonCode() const |
[read-only, since 5.12]
sharedSubscription : const boolThis property holds whether the subscription is shared.
This property was introduced in Qt 5.12.
Access functions:
bool | isSharedSubscription() const |
[read-only, since 5.12]
sharedSubscriptionName : const QStringThis property holds the name of the shared subscription.
This property was introduced in Qt 5.12.
Access functions:
QString | sharedSubscriptionName() const |
[read-only]
state : const SubscriptionStateThis property holds the state of the subscription.
Access functions:
QMqttSubscription::SubscriptionState | state() const |
Notifier signal:
void | stateChanged(QMqttSubscription::SubscriptionState state) |
[read-only]
topic : const QMqttTopicFilterThis property holds the topic of the subscription.
Access functions:
QMqttTopicFilter | topic() const |
[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().
[override virtual]
QMqttSubscription::~QMqttSubscription()Deletes a subscription. If the topic was not already unsubscribed from, it will be unsubscribed from automatically.
[since 5.12]
QMqttUserProperties QMqttSubscription::userProperties() constReturns 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.
This function was introduced in Qt 5.12.