このページでは

QMqttTopicFilter Class

QMqttTopicFilter クラスは、MQTT トピックフィルターを表します。詳細...

ヘッダー: #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 QLatin1String &filter)
QMqttTopicFilter(const QString &filter = QString())
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 は、QString をラップした薄いラッパーであり、MQTT トピックフィルタのための表現力豊かなデータ型を提供します。意図しない誤用を防ぐ強型であるという利点に加え、QMqttTopicFilter は、isValid() やmatch() といった、トピックフィルタに関連する便利な関数も提供します。

たとえば、以下のコードはコンパイルエラーとなり、特に変数名が表現力に欠ける場合、2つのフィルタが意図せず、かつ無意味に一致してしまうのを防ぐことができます:

QMqttTopicFilter globalFilter{"foo/#"};
QMqttTopicFilter specificFilter{"foo/bar"};
if (globalFilter.match(specificFilter)) {
    //...
}

ただし、以下のスニペットは期待通りにコンパイルされ、実行されるため、使い勝手には影響しません:

QMqttTopicFilter globalFilter{"foo/#"};
if (globalFilter.match("foo/bar")) {
    //...
}

QMqttTopicNameも参照してください 。

メンバ型のドキュメント

enum QMqttTopicFilter::MatchOption
flags QMqttTopicFilter::MatchOptions

この列挙型値は、トピックフィルターのマッチングオプションを保持します。

定数値説明
QMqttTopicFilter::NoMatchOption0x0000一致オプションは設定されていません。
QMqttTopicFilter::WildcardsDontMatchDollarTopicMatchOption0x0001フィルタの先頭にワイルドカードがある場合、ドル記号 ($) で始まるトピック名とは一致しません。

MatchOptions 型は、QFlags<MatchOption> の typedef です。これは、MatchOption 値の OR 組み合わせを格納します。

メンバ関数のドキュメント

QMqttTopicFilter::QMqttTopicFilter(const QLatin1String &filter)

指定されたfilter を使用して、新しいMQTTトピックフィルターを作成します。

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

指定されたfilter を使用して、新しいMQTTトピックフィルターを作成します。

QMqttTopicFilter::QMqttTopicFilter(const QMqttTopicFilter &filter)

filter のコピーとして、新しい MQTT トピックフィルターを作成します。

[noexcept] QMqttTopicFilter::~QMqttTopicFilter()

QMqttTopicFilter オブジェクトを破棄します。

QString QMqttTopicFilter::filter() const

トピックフィルターを返します。

setFilter()も参照してください 。

bool QMqttTopicFilter::isValid() const

トピックフィルタがMQTT標準の4.7節に従って有効である場合はtrue を返し、それ以外の場合はfalse を返します。

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

トピックフィルターが、指定されたmatchOptions に従ったトピック名name と一致する場合はtrue を返し、それ以外の場合はfalse を返します。

void QMqttTopicFilter::setFilter(const QString &filter)

トピックフィルターを「filter 」に設定します。

filter()も参照してください 。

QString QMqttTopicFilter::sharedSubscriptionName() const

トピックフィルターが共有サブスクリプションとして指定されている場合、その共有サブスクリプションの名前を返します。共有サブスクリプションの形式は、$share/sharename/topicfilter として定義されています。

[noexcept] void QMqttTopicFilter::swap(QMqttTopicFilter &other)

MQTTトピックフィルター「other 」を、このMQTTトピックフィルターと入れ替えます。この操作は非常に高速で、失敗することはありません。

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

このオブジェクトに MQTT トピックフィルター「filter 」を割り当て、そのコピーへの参照を返します。

関連する非メンバー

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

トピックフィルター `lhs ` と `rhs ` が異なる場合は `true ` を返し、そうでない場合は `false` を返します。

[noexcept] bool operator<(const QMqttTopicFilter &lhs, const QMqttTopicFilter &rhs)

トピックフィルター `lhs ` がトピックフィルター `rhs` より辞書順で小さい場合、true を返します。そうでない場合は、false を返します。

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

トピックフィルタ `filter ` をストリーム `out ` に書き込み、そのストリームへの参照を返します。

「QDataStream 演算子の形式」も参照してください 。

[noexcept] bool operator==(const QMqttTopicFilter &lhs, const QMqttTopicFilter &rhs)

トピックフィルター `lhs ` と `rhs ` が等しい場合は `true ` を返し、そうでない場合は `false` を返します。

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

ストリーム `in ` からトピックフィルターを読み取り、filter に読み込み、そのストリームへの参照を返します。

「QDataStream 演算子の形式」も参照してください 。

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