QMqttTopicFilter Class

The QMqttTopicFilter class represents a MQTT topic filter. More...

Header: #include <QMqttTopicFilter>
qmake: QT += mqtt

Note: All functions in this class are reentrant.

Public Types

enum MatchOption { NoMatchOption, WildcardsDontMatchDollarTopicMatchOption }
flags MatchOptions

Public Functions

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) const
void setFilter(const QString &filter)
void swap(QMqttTopicFilter &other)
QMqttTopicFilter &operator=(const QMqttTopicFilter &filter)
QMqttTopicFilter &operator=(QMqttTopicFilter &&other)
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)

Detailed Description

The QMqttTopicFilter class represents a MQTT topic 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() 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.

Member Type Documentation

enum QMqttTopicFilter::MatchOption
flags QMqttTopicFilter::MatchOptions

This enum value holds the matching options for the topic filter.

ConstantValueDescription
QMqttTopicFilter::NoMatchOption0x0000No match options are set.
QMqttTopicFilter::WildcardsDontMatchDollarTopicMatchOption0x0001A 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.

Member Function Documentation

QMqttTopicFilter::QMqttTopicFilter(const QString &filter = QString())

Creates a new MQTT topic filter with the specified filter.

QMqttTopicFilter::QMqttTopicFilter(const QLatin1String &filter)

Creates a new MQTT topic filter with the specified filter.

QMqttTopicFilter::QMqttTopicFilter(const QMqttTopicFilter &filter)

Creates a new MQTT topic filter as a copy of filter.

QMqttTopicFilter::~QMqttTopicFilter()

Destroys the QMqttTopicFilter object.

QString QMqttTopicFilter::filter() const

Returns the topic filter.

See also setFilter().

bool QMqttTopicFilter::isValid() const

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

bool QMqttTopicFilter::match(const QMqttTopicName &name, QMqttTopicFilter::MatchOptions matchOptions) const

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

void QMqttTopicFilter::setFilter(const QString &filter)

Sets the topic filter to filter.

See also filter().

void QMqttTopicFilter::swap(QMqttTopicFilter &other)

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

QMqttTopicFilter &QMqttTopicFilter::operator=(const QMqttTopicFilter &filter)

Assigns the MQTT topic filter filter to this object, and returns a reference to the copy.

QMqttTopicFilter &QMqttTopicFilter::operator=(QMqttTopicFilter &&other)

Move-assignment operator.

Related Non-Members

bool operator!=(const QMqttTopicFilter &lhs, const QMqttTopicFilter &rhs)

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

bool operator<(const QMqttTopicFilter &lhs, const QMqttTopicFilter &rhs)

Returns true if the topic filter lhs is lexically less than the topic filter rhs; otherwise returns false.

QDataStream &operator<<(QDataStream &out, const QMqttTopicFilter &filter)

Writes the topic filter filter to the stream out and returns a reference to the stream.

See also Format of the QDataStream operators.

bool operator==(const QMqttTopicFilter &lhs, const QMqttTopicFilter &rhs)

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

QDataStream &operator>>(QDataStream &in, QMqttTopicFilter &filter)

Reads a topic filter into filter from the stream in and returns a reference to the stream.

See also Format of the QDataStream operators.

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