The QMqttSubscription class receives notifications from an MQTT broker about a specified topic. 更多...
头: | #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 ) |
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]
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.
访问函数:
QString | reason () const |
[read-only]
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.
访问函数:
QMqtt::ReasonCode | reasonCode () const |
[read-only]
sharedSubscription
: const
bool
This property holds whether the subscription is shared.
访问函数:
bool | isSharedSubscription () const |
[read-only]
sharedSubscriptionName
: const
QString
This property holds the name of the shared subscription.
访问函数:
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 |
[override virtual]
QMqttSubscription::
~QMqttSubscription
()
Deletes a subscription. If the topic was not already unsubscribed from, it will be unsubscribed from automatically.
[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 ().
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 .