The QMqttTopicFilter class represents a MQTT topic filter. 更多...
头: | #include <QMqttTopicFilter> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Mqtt)
target_link_libraries(mytarget PRIVATE Qt6::Mqtt) |
qmake: | QT += mqtt |
注意: 此类的所有函数 可重入 .
enum | MatchOption { NoMatchOption, WildcardsDontMatchDollarTopicMatchOption } |
flags | MatchOptions |
QMqttTopicFilter (const QString & filter = QString()) | |
QMqttTopicFilter (const QLatin1String & filter ) | |
QMqttTopicFilter (const QMqttTopicFilter & filter ) | |
~QMqttTopicFilter () | |
QString | filter () const |
bool | isValid () const |
bool | match (const QMqttTopicName & name , QMqttTopicFilter::MatchOptions matchOptions = NoMatchOption) const |
void | setFilter (const QString & filter ) |
QString | sharedSubscriptionName () const |
void | swap (QMqttTopicFilter & other ) |
QMqttTopicFilter & | operator= (const QMqttTopicFilter & filter ) |
bool | operator!= (const QMqttTopicFilter & lhs , const QMqttTopicFilter & rhs ) |
bool | operator< (const QMqttTopicFilter & lhs , const QMqttTopicFilter & rhs ) |
QDataStream & | operator<< (QDataStream & out , const QMqttTopicFilter & filter ) |
bool | operator== (const QMqttTopicFilter & lhs , const QMqttTopicFilter & rhs ) |
QDataStream & | operator>> (QDataStream & in , QMqttTopicFilter & filter ) |
QMqttTopicFilter is a thin wrapper around a QString providing an expressive data type for MQTT topic filters. Beside the benefits of having a strong type preventing unintended misuse, QMqttTopicFilter provides convenient functions related to topic filters like isValid () 或 match ().
For example, the following code would fail to compile and prevent a possible unintended and meaningless matching of two filters, especially if the variable names were less expressive:
QMqttTopicFilter globalFilter{"foo/#"}; QMqttTopicFilter specificFilter{"foo/bar"}; if (globalFilter.match(specificFilter)) { //... }
The usability, however, is not affected since the following snippet compiles and runs as expected:
QMqttTopicFilter globalFilter{"foo/#"}; if (globalFilter.match("foo/bar")) { //... }
另请参阅 QMqttTopicName .
This enum value holds the matching options for the topic filter.
常量 | 值 | 描述 |
---|---|---|
QMqttTopicFilter::NoMatchOption
|
0x0000
|
No match options are set. |
QMqttTopicFilter::WildcardsDontMatchDollarTopicMatchOption
|
0x0001
|
A wildcard at the filter's beginning does not match a topic name that starts with the dollar sign ($). |
The MatchOptions type is a typedef for QFlags <MatchOption>. It stores an OR combination of MatchOption values.
Creates a new MQTT topic filter with the specified filter .
Creates a new MQTT topic filter with the specified filter .
Creates a new MQTT topic filter as a copy of filter .
[noexcept]
QMqttTopicFilter::
~QMqttTopicFilter
()
销毁 QMqttTopicFilter 对象。
Returns the topic filter.
另请参阅 setFilter ().
返回
true
if the topic filter is valid according to the MQTT standard section 4.7, or
false
否则。
返回
true
if the topic filter matches the topic name
name
honoring the given
matchOptions
,或
false
否则。
Sets the topic filter to filter .
另请参阅 filter ().
Returns the name of a share if the topic filter has been specified as a shared subscription. The format of shared subscriptions is defined as
$share/sharename/topicfilter
.
[noexcept]
void
QMqttTopicFilter::
swap
(
QMqttTopicFilter
&
other
)
Swaps the MQTT topic filter other with this MQTT topic filter. This operation is very fast and never fails.
Assigns the MQTT topic filter filter to this object, and returns a reference to the copy.
[noexcept]
bool
operator!=
(const
QMqttTopicFilter
&
lhs
, const
QMqttTopicFilter
&
rhs
)
返回
true
if the topic filters
lhs
and
rhs
不同,否则返回
false
.
[noexcept]
bool
operator<
(const
QMqttTopicFilter
&
lhs
, const
QMqttTopicFilter
&
rhs
)
返回
true
if the topic filter
lhs
is lexically less than the topic filter
rhs
;否则返回
false
.
Writes the topic filter filter 到流 out 并返回流引用。
另请参阅 QDataStream 运算符格式 .
[noexcept]
bool
operator==
(const
QMqttTopicFilter
&
lhs
, const
QMqttTopicFilter
&
rhs
)
返回
true
if the topic filters
lhs
and
rhs
相等,否则返回
false
.
Reads a topic filter into filter 从流 in 并返回流引用。
另请参阅 QDataStream 运算符格式 .