QMqttMessage Class
QMqttMessage 类提供了有关基于订阅从消息代理接收到的消息的信息。更多内容...
| 头文件: | #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 级别为 1 或 2 时,才会出现重复消息。
访问函数:
| bool | duplicate() const |
[read-only] id : const quint16
该属性存储消息的ID。
ID 用于 QoS 级别大于零的消息。
访问函数:
| 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 。
© 2026 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.