PySide6.QtMqtt.QMqttTopicFilter

class QMqttTopicFilter

The QMqttTopicFilter class represents a MQTT topic filter. More

Synopsis

Methods

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 like isValid() or 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")) {
    //...
}

See also

QMqttTopicName

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:

filterQLatin1String

Creates a new MQTT topic filter with the specified filter.

__init__(filter)
Parameters:

filterQMqttTopicFilter

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

setFilter()

isValid()
Return type:

bool

Returns true if the topic filter is valid according to the MQTT standard section 4.7, or false otherwise.

match(name[, matchOptions=QMqttTopicFilter.MatchOption.NoMatchOption])
Parameters:
Return type:

bool

Returns true if the topic filter matches the topic name name honoring the given matchOptions, or false otherwise.

__ne__(rhs)
Parameters:

rhsQMqttTopicFilter

Return type:

bool

Returns true if the topic filters lhs and rhs are different, otherwise returns false.

setFilter(filter)
Parameters:

filter – str

Sets the topic filter to filter.

See also

filter()

sharedSubscriptionName()
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:

otherQMqttTopicFilter

Swaps the MQTT topic filter other with this MQTT topic filter. This operation is very fast and never fails.