本页内容

QCoapOption Class

QCoapOption 类用于存储有关 CoAP 选项的数据。更多内容...

头文件: #include <QCoapOption>
CMake: find_package(Qt6 REQUIRED COMPONENTS Coap)
target_link_libraries(mytarget PRIVATE Qt6::Coap)
qmake: QT += coap

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

公共类型

enum OptionName { Invalid, IfMatch, UriHost, Etag, IfNoneMatch, …, Size1 }

公共函数

QCoapOption(QCoapOption::OptionName name = Invalid, const QByteArray &opaqueValue = QByteArray())
QCoapOption(QCoapOption::OptionName name, const QString &stringValue)
QCoapOption(QCoapOption::OptionName name, quint32 intValue)
QCoapOption(const QCoapOption &other)
QCoapOption(QCoapOption &&other)
~QCoapOption()
bool isValid() const
int length() const
QCoapOption::OptionName name() const
QByteArray opaqueValue() const
QString stringValue() const
void swap(QCoapOption &other)
quint32 uintValue() const
bool operator!=(const QCoapOption &other) const
QCoapOption &operator=(QCoapOption &&other)
QCoapOption &operator=(const QCoapOption &other)
bool operator==(const QCoapOption &other) const

详细说明

CoAP 定义了可包含在消息中的若干选项。请求和响应均可包含一个或多个选项的列表。例如,请求中的 URI 通过多个选项进行传输,而 HTTP 中通常在 HTTP 头中携带的元数据,在此也作为选项提供。

一个选项包含一个名称(与选项 ID 相关)和一个值。名称是OptionName 枚举中的一个值。

成员类型文档

enum QCoapOption::OptionName

表示选项的名称。每个 ID 的值均符合 CoAP 标准的规定,但“Invalid”除外。更多详细信息请参阅RFC 7252和RFC 7959。

常量值描述
QCoapOption::Invalid0一个无效的选项。
QCoapOption::IfMatch1If-Match 选项。
QCoapOption::UriHost3Uri-Host 选项。
QCoapOption::Etag4Etag 选项。
QCoapOption::IfNoneMatch5If-None-Match 选项。
QCoapOption::Observe6Observe 选项。
QCoapOption::UriPort7Uri-Port 选项。
QCoapOption::LocationPath8Location-path 选项。
QCoapOption::UriPath11Uri-Path 选项。
QCoapOption::ContentFormat12Content-Format 选项。
QCoapOption::MaxAge14Max-Age 选项。
QCoapOption::UriQuery15Uri-Query 选项。
QCoapOption::Accept17Accept 选项。
QCoapOption::LocationQuery20Location-Query 选项。
QCoapOption::Block223Block2 选项。
QCoapOption::Block127Block1 选项。
QCoapOption::Size228Size2 选项。
QCoapOption::ProxyUri35Proxy-Uri 选项。
QCoapOption::ProxyScheme39Proxy-Scheme 选项。
QCoapOption::Size160Size1 选项。

成员函数文档

QCoapOption::QCoapOption(QCoapOption::OptionName name = Invalid, const QByteArray &opaqueValue = QByteArray())

根据给定的name 和QByteArray opaqueValue ,构建一个新的CoAP选项。如果未传递任何参数,则构建一个Invalid对象。

另请参阅 isValid()。

QCoapOption::QCoapOption(QCoapOption::OptionName name, const QString &stringValue)

根据给定的name 和QString stringValue ,构建一个新的CoAP选项。

另请参阅 isValid()。

QCoapOption::QCoapOption(QCoapOption::OptionName name, quint32 intValue)

根据给定的name 和无符号整数intValue ,构建一个新的CoAP选项。

另请参阅 isValid()。

QCoapOption::QCoapOption(const QCoapOption &other)

创建一个新的 CoAP 选项,作为other 的副本,使这两个选项完全相同。

另请参阅 isValid()。

QCoapOption::QCoapOption(QCoapOption &&other)

将一个 QCoapOption 进行移动构造,使其指向与 `other ` 所指向的同一对象。

[noexcept] QCoapOption::~QCoapOption()

销毁QCoapOption 对象。

bool QCoapOption::isValid() const

如果该选项有效,则返回true 。

int QCoapOption::length() const

返回该选项值的长度。

QCoapOption::OptionName QCoapOption::name() const

返回该选项的名称。

QByteArray QCoapOption::opaqueValue() const

返回该选项的值。

QString QCoapOption::stringValue() const

返回该选项的QString 值。

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

将此选项与other 互换。该操作速度极快,且绝不会失败。

quint32 QCoapOption::uintValue() const

返回该选项的整数值。

注意:uint 类型的选项 最多占用 4 字节。如果选项值长度超过 4 字节,则仅使用其低 4 字节来计算结果;请使用 `length()` 来检测值是否过长。

bool QCoapOption::operator!=(const QCoapOption &other) const

如果此QCoapOption 与other 不同,则返回true 。

[noexcept] QCoapOption &QCoapOption::operator=(QCoapOption &&other)

将other 移入此选项,并返回对QCoapOption 的引用。

QCoapOption &QCoapOption::operator=(const QCoapOption &other)

将other 复制到此选项中,使这两个选项完全一致。返回对QCoapOption 的引用。

bool QCoapOption::operator==(const QCoapOption &other) const

如果此QCoapOption 和other 相等,则返回true 。

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