QMqttMessage Class
QMqttMessage 类提供从基于订阅的消息代理接收到的消息的相关信息。更多
Header: | #include <QMqttMessage> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Mqtt) target_link_libraries(mytarget PRIVATE Qt6::Mqtt) |
qmake: | QT += mqtt |
属性
公共功能
QMqttMessage() | |
QMqttMessage(const QMqttMessage &other) | |
bool | duplicate() const |
quint16 | id() const |
const QByteArray & | payload() const |
QMqttPublishProperties | publishProperties() const |
quint8 | qos() const |
bool | retain() const |
QMqttTopicName | topic() const |
bool | operator!=(const QMqttMessage &other) const |
QMqttMessage & | operator=(const QMqttMessage &other) |
bool | operator==(const QMqttMessage &other) const |
详细说明
在模块内部创建 MQTT 消息,并通过QMqttSubscription::messageReceived() 信号返回。
属性文档
[read-only]
duplicate : const bool
该属性表示信息是否重复。
重复报文表明报文已在早些时候发送,但尚未得到确认。因此,代理假定它需要重新发送以验证报文本身的传输。只有当 QoS 级别为一或二时,才会出现重复报文。
访问功能:
bool | duplicate() const |
[read-only]
id : const quint16
该属性包含报文的 ID。
ID 用于 QoS 级别高于 0 的报文。
访问功能:
quint16 | id() const |
[read-only]
payload : const QByteArray
该属性包含信息的有效载荷。
访问功能:
const QByteArray & | payload() const |
[read-only]
qos : const quint8
该属性表示信息的 QoS 级别。
访问功能:
quint8 | qos() const |
[read-only]
retain : const bool
该属性表示消息是否被保留。
保留的消息会保留在代理上,供未来的客户端订阅。因此,保留信息是以前创建的,而不是实时更新。一个代理只能为每个主题存储一条保留信息。
访问功能:
bool | retain() const |
[read-only]
topic : const QMqttTopicName
该属性包含邮件主题。
如果订阅使用了通配符,则描述与该订阅匹配的主题。该属性从不包含通配符。
访问函数
QMqttTopicName | topic() const |
成员函数文档
QMqttMessage::QMqttMessage()
创建新的 MQTT 消息。
QMqttMessage::QMqttMessage(const QMqttMessage &other)
构建一条新的 MQTT 消息,它是other 的副本。
QMqttPublishProperties QMqttMessage::publishProperties() const
返回作为信息一部分接收到的发布属性。
注意: 此函数仅指定收到发布信息时的属性。当发布信息时,QoS 值为 1 或 2 的信息可能包含附加属性。这些属性可通过QMqttClient::messageStatusChanged 信号获取。
注意: 只有当客户端将QMqttClient::MQTT_5_0 指定为QMqttClient::ProtocolVersion 时,此函数才会提供有效数据。
bool QMqttMessage::operator!=(const QMqttMessage &other) const
如果信息和other 不相等,则返回true
,否则返回false
。
QMqttMessage &QMqttMessage::operator=(const QMqttMessage &other)
使该对象成为other 的副本,并返回该对象的新值。
bool QMqttMessage::operator==(const QMqttMessage &other) const
如果信息和other 相等,则返回true
,否则返回false
。
© 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.