本页内容

QMqttTopicName Class

QMqttTopicName 类表示一个 MQTT 主题名称。更多内容...

头文件: #include <QMqttTopicName>
CMake: find_package(Qt6 REQUIRED COMPONENTS Mqtt)
target_link_libraries(mytarget PRIVATE Qt6::Mqtt)
qmake: QT += mqtt

注意:该类中的所有函数均为可重入函数。

公共函数

QMqttTopicName(const QLatin1String &name)
QMqttTopicName(const QString &name = QString())
QMqttTopicName(const QMqttTopicName &name)
~QMqttTopicName()
bool isValid() const
int levelCount() const
QStringList levels() const
QString name() const
void setName(const QString &name)
void swap(QMqttTopicName &other)
QMqttTopicName &operator=(const QMqttTopicName &name)
bool operator!=(const QMqttTopicName &lhs, const QMqttTopicName &rhs)
bool operator<(const QMqttTopicName &lhs, const QMqttTopicName &rhs)
QDataStream &operator<<(QDataStream &out, const QMqttTopicName &name)
bool operator==(const QMqttTopicName &lhs, const QMqttTopicName &rhs)
QDataStream &operator>>(QDataStream &in, QMqttTopicName &name)

详细说明

QMqttTopicName 是围绕QString 构建的一个轻量级封装类,为MQTT主题名称提供了一个表达力强的数据类型。除了具有强类型能防止意外误用这一优点外,QMqttTopicName 还提供了与主题名称相关的便捷函数,例如isValid() 或levels()。

另请参阅 QMqttTopicFilter 。

成员函数文档

QMqttTopicName::QMqttTopicName(const QLatin1String &name)

使用指定的name 创建一个新的MQTT主题名称。

QMqttTopicName::QMqttTopicName(const QString &name = QString())

使用指定的name 创建一个新的MQTT主题名称。

QMqttTopicName::QMqttTopicName(const QMqttTopicName &name)

创建一个新的 MQTT 主题名称,该名称是name 的副本。

[noexcept] QMqttTopicName::~QMqttTopicName()

销毁QMqttTopicName 对象。

bool QMqttTopicName::isValid() const

如果主题名称符合 MQTT 标准第 4.7 节的规定,则返回 `true `;否则返回 `false `。

int QMqttTopicName::levelCount() const

返回主题层级的总数。

QStringList QMqttTopicName::levels() const

返回主题级别。

QString QMqttTopicName::name() const

返回主题名称。

另请参阅 setName()。

void QMqttTopicName::setName(const QString &name)

将主题名称设置为name 。

另请参阅 name()。

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

将 MQTT 主题名other 替换为此 MQTT 主题名。此操作速度极快,且绝不会失败。

QMqttTopicName &QMqttTopicName::operator=(const QMqttTopicName &name)

将 MQTT 主题名name 分配给此对象,并返回该副本的引用。

相关的非成员

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

如果主题名lhs 和rhs 不同,则返回true ;否则返回false 。

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

如果主题名lhs 在字典序上小于主题名rhs ,则返回true ;否则返回false 。

QDataStream &operator<<(QDataStream &out, const QMqttTopicName &name)

将主题名称name 写入流out ,并返回该流的引用。

另请参阅 QDataStream 运算符的格式。

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

如果主题名lhs 和rhs 相等,则返回true ;否则返回false 。

QDataStream &operator>>(QDataStream &in, QMqttTopicName &name)

从流in 中读取主题名称并将其读入name ,同时返回该流的引用。

另请参阅 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.