PySide6.QtMqtt.QMqttTopicFilter¶
- class QMqttTopicFilter¶
The
QMqttTopicFilter
class represents a MQTT topic filter. More…Synopsis¶
Methods¶
def
__init__()
def
filter()
def
isValid()
def
match()
def
__ne__()
def
setFilter()
def
swap()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
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 likeisValid()
ormatch()
.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")) { //... }
See also
- class MatchOption¶
(inherits
enum.Flag
) This enum value holds the matching options for the topic filter.Constant
Description
QMqttTopicFilter.NoMatchOption
No match options are set.
QMqttTopicFilter.WildcardsDontMatchDollarTopicMatchOption
A wildcard at the filter’s beginning does not match a topic name that starts with the dollar sign ($).
- __init__(filter)¶
- Parameters:
filter –
QLatin1String
Creates a new MQTT topic filter with the specified
filter
.- __init__(filter)
- Parameters:
filter –
QMqttTopicFilter
Creates a new MQTT topic filter as a copy of
filter
.- __init__([filter=""])
- Parameters:
filter – str
Creates a new MQTT topic filter with the specified
filter
.- filter()¶
- Return type:
str
Returns the topic filter.
See also
- isValid()¶
- Return type:
bool
Returns
true
if the topic filter is valid according to the MQTT standard section 4.7, orfalse
otherwise.- match(name[, matchOptions=QMqttTopicFilter.MatchOption.NoMatchOption])¶
- Parameters:
name –
QMqttTopicName
matchOptions – Combination of
MatchOption
- Return type:
bool
Returns
true
if the topic filter matches the topic namename
honoring the givenmatchOptions
, orfalse
otherwise.- __ne__(rhs)¶
- Parameters:
rhs –
QMqttTopicFilter
- Return type:
bool
Returns
true
if the topic filterslhs
andrhs
are different, otherwise returnsfalse
.- setFilter(filter)¶
- Parameters:
filter – str
Sets the topic filter to
filter
.See also
- Return type:
str
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
.- swap(other)¶
- Parameters:
other –
QMqttTopicFilter
Swaps the MQTT topic filter
other
with this MQTT topic filter. This operation is very fast and never fails.