QMqttPublishProperties Class

The QMqttPublishProperties class represents configuration options for sending or receiving a message. More...

Header: #include <QMqttPublishProperties>
CMake: find_package(Qt6 REQUIRED COMPONENTS Mqtt)
target_link_libraries(mytarget PRIVATE Qt6::Mqtt)
qmake: QT += mqtt

Public Types

enum PublishPropertyDetail { None, PayloadFormatIndicator, MessageExpiryInterval, TopicAlias, ResponseTopic, …, ContentType }
flags PublishPropertyDetails

Public Functions

QMqttPublishProperties::PublishPropertyDetails availableProperties() const
QString contentType() const
QByteArray correlationData() const
quint32 messageExpiryInterval() const
QMqtt::PayloadFormatIndicator payloadFormatIndicator() const
QString responseTopic() const
void setContentType(const QString &type)
void setCorrelationData(const QByteArray &correlation)
void setMessageExpiryInterval(quint32 interval)
void setPayloadFormatIndicator(QMqtt::PayloadFormatIndicator indicator)
void setResponseTopic(const QString &topic)
void setSubscriptionIdentifiers(const QList<quint32> &ids)
void setTopicAlias(quint16 alias)
void setUserProperties(const QMqttUserProperties &properties)
QList<quint32> subscriptionIdentifiers() const
quint16 topicAlias() const
QMqttUserProperties userProperties() const

Detailed Description

Invoking QMqttClient::publish() to send a message to a broker can include QMqttPublishProperties to provide additional arguments on how the message should be treated on the broker.

Furthermore receiving a message by an instantiated subscription might contain publish properties which have been forwarded or adapted by the server.

Note: Publish properties are part of the MQTT 5.0 specification and cannot be used when connecting with a lower protocol level. See QMqttClient::ProtocolVersion for more information.

Member Type Documentation

enum QMqttPublishProperties::PublishPropertyDetail
flags QMqttPublishProperties::PublishPropertyDetails

This enum type specifies the available properties set by the server or the client when creating a message.

ConstantValueDescription
QMqttPublishProperties::None0x00000000No property has been specified.
QMqttPublishProperties::PayloadFormatIndicator0x00000001The type of content of the message.
QMqttPublishProperties::MessageExpiryInterval0x00000002The duration a message is valid.
QMqttPublishProperties::TopicAlias0x00000004The topic alias for this message.
QMqttPublishProperties::ResponseTopic0x00000008The topic the receipient should respond to.
QMqttPublishProperties::CorrelationData0x00000010An identifier of the response message.
QMqttPublishProperties::UserProperty0x00000020Additional properties set by the user.
QMqttPublishProperties::SubscriptionIdentifier0x00000040An identifier of subscriptions matching the publication.
QMqttPublishProperties::ContentType0x00000080A description of the content of the message.

The PublishPropertyDetails type is a typedef for QFlags<PublishPropertyDetail>. It stores an OR combination of PublishPropertyDetail values.

Member Function Documentation

QMqttPublishProperties::PublishPropertyDetails QMqttPublishProperties::availableProperties() const

Returns the available properties specified in this instance. When a message is created, it does not need to include all properties. This function serves as an indicator of those properties which have been explicitly set.

QString QMqttPublishProperties::contentType() const

Returns the content type of the message.

See also setContentType().

QByteArray QMqttPublishProperties::correlationData() const

Returns the correlation data.

See also setCorrelationData().

quint32 QMqttPublishProperties::messageExpiryInterval() const

Returns the message expiry interval. This value specifies the number of seconds a server is allowed to forward the message. If the interval expires, the server must delete the message and abort publishing it.

See also setMessageExpiryInterval().

QMqtt::PayloadFormatIndicator QMqttPublishProperties::payloadFormatIndicator() const

Returns the payload format indicator.

See also setPayloadFormatIndicator().

QString QMqttPublishProperties::responseTopic() const

Returns the response topic a user should use as a follow up to a request.

See also setResponseTopic().

void QMqttPublishProperties::setContentType(const QString &type)

Sets the content type of the message to type.

See also contentType().

void QMqttPublishProperties::setCorrelationData(const QByteArray &correlation)

Sets the correlation data to correlation.

See also correlationData().

void QMqttPublishProperties::setMessageExpiryInterval(quint32 interval)

Sets the message expiry interval to interval.

See also messageExpiryInterval().

void QMqttPublishProperties::setPayloadFormatIndicator(QMqtt::PayloadFormatIndicator indicator)

Sets the payload format indicator to indicator.

See also payloadFormatIndicator().

void QMqttPublishProperties::setResponseTopic(const QString &topic)

Sets the response topic to topic.

See also responseTopic().

void QMqttPublishProperties::setSubscriptionIdentifiers(const QList<quint32> &ids)

Sets the subscription identifiers to ids.

See also subscriptionIdentifiers().

void QMqttPublishProperties::setTopicAlias(quint16 alias)

Sets the topic alias for publishing a message to alias. A topic alias value must be greater than zero and less than the maximum topic alias specified by the server.

See also topicAlias() and QMqttServerConnectionProperties::maximumTopicAlias().

void QMqttPublishProperties::setUserProperties(const QMqttUserProperties &properties)

Sets the user properties of a message to properties.

See also userProperties().

QList<quint32> QMqttPublishProperties::subscriptionIdentifiers() const

Returns the subscription identifiers of subscriptions matching the topic filter of the message.

See also setSubscriptionIdentifiers().

quint16 QMqttPublishProperties::topicAlias() const

Returns the topic alias used for publishing a message.

See also setTopicAlias().

QMqttUserProperties QMqttPublishProperties::userProperties() const

Returns the user properties of a message.

See also setUserProperties().

© 2023 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.