QMqttSubscription Class

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

头: #include <QMqttSubscription>
qmake: QT += mqtt
继承: 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 )

详细描述

成员类型文档编制

enum QMqttSubscription:: SubscriptionState

This enum type describes the states a subscription can have.

常量 描述
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 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.

访问函数:

quint8 qos () const

通知程序信号:

void qosChanged (quint8)

[read-only, since 5.12] 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.

该特性在 Qt 5.12 引入。

访问函数:

QString reason () const

[read-only, since 5.12] 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.

该特性在 Qt 5.12 引入。

访问函数:

QMqtt::ReasonCode reasonCode () const

[read-only, since 5.12] sharedSubscription : const bool

This property holds whether the subscription is shared.

该特性在 Qt 5.12 引入。

访问函数:

bool isSharedSubscription () const

[read-only, since 5.12] sharedSubscriptionName : const QString

This property holds the name of the shared subscription.

该特性在 Qt 5.12 引入。

访问函数:

QString sharedSubscriptionName () const

[read-only] state : const SubscriptionState

This property holds the state of the subscription.

访问函数:

QMqttSubscription::SubscriptionState state () const

通知程序信号:

void stateChanged (QMqttSubscription::SubscriptionState state )

[read-only] topic : const QMqttTopicFilter

This property holds the topic of the subscription.

访问函数:

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 .

注意: 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 () const

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

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

该函数在 Qt 5.12 引入。