QMqttSubscription Class
QMqttSubscription 类从 MQTT 代理接收关于指定主题的通知。更多
Header: | #include <QMqttSubscription> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Mqtt) target_link_libraries(mytarget PRIVATE Qt6::Mqtt) |
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
该枚举类型描述了订阅可能具有的状态。
常量 | 值 | 说明 |
---|---|---|
QMqttSubscription::Unsubscribed | 0 | 主题已被取消订阅。 |
QMqttSubscription::SubscriptionPending | 1 | 已发送订阅请求,但尚未得到代理的确认。 |
QMqttSubscription::Subscribed | 2 | 订阅成功,将收到消息。 |
QMqttSubscription::UnsubscriptionPending | 3 | 已发送取消订阅主题的请求,但代理尚未确认。 |
QMqttSubscription::Error | 4 | 发生错误。 |
属性文档
[read-only]
qos : const quint8
该属性用于保存订阅的 QoS 级别。
订阅的 QoS 级别指定了客户端接收信息的最大QoS 级别。发布者仍可以较低的级别发送信息。
访问功能:
quint8 | qos() const |
通知者信号:
void | qosChanged(quint8) |
[read-only]
reason : const QString
此属性包含订阅的原因字符串。
服务器使用原因字符串提供有关订阅的附加信息。服务器可选择是否发送。
访问功能:
QString | reason() const |
[read-only]
reasonCode : const QMqtt::ReasonCode
该属性包含订阅的原因代码。
原因代码指定订阅失败时的错误类型,或成功时的 QoS 级别。
访问功能:
QMqtt::ReasonCode | reasonCode() const |
[read-only]
sharedSubscription : const bool
此属性表示订阅是否共享。
访问功能:
bool | isSharedSubscription() const |
[read-only]
sharedSubscriptionName : const QString
此属性包含共享订阅的名称。
访问功能:
QString | sharedSubscriptionName() const |
[read-only]
state : const SubscriptionState
此属性保存订阅的状态。
访问功能:
QMqttSubscription::SubscriptionState | state() const |
通知者信号:
void | stateChanged(QMqttSubscription::SubscriptionState state) |
[read-only]
topic : const QMqttTopicFilter
该属性包含订阅的主题。
访问功能:
QMqttTopicFilter | topic() const |
成员函数文档
[override virtual noexcept]
QMqttSubscription::~QMqttSubscription()
删除订阅。如果topic 尚未取消订阅,则会自动取消订阅。
[signal]
void QMqttSubscription::messageReceived(QMqttMessage msg)
收到新信息msg 时发出该信号。
[slot]
void QMqttSubscription::unsubscribe()
从topic 取消订阅。
注: 这可能会影响QMqttClient::subscribe() 返回的所有共享指针实例。
QMqttUserProperties QMqttSubscription::userProperties() const
返回订阅被接受时从代理处收到的用户属性。
注意: 只有当客户端指定QMqttClient::MQTT_5_0 为QMqttClient::ProtocolVersion 时,该函数才会提供有效数据。
© 2025 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.