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 头中携带的元数据也会作为选项提供。

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

成员类型文档

enum QCoapOption::OptionName

表示一个选项的名称。除无效(Invalid)外,每个 ID 的值均由 CoAP 标准规定。详情请参考RFC 7252RFC 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::ContentFormat12内容格式(Content-Format)选项。
QCoapOption::MaxAge14Max-Age 选项
QCoapOption::UriQuery15Uri-Query 选项
QCoapOption::Accept17接受选项
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())

使用给定的nameQByteArray opaqueValue 构造一个新的 CoAP 选项。如果没有传递参数,则构造一个无效对象。

另请参阅 isValid().

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

用给定的nameQString 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)

Move-构建一个 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

返回选项的整数值。

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

如果QCoapOptionother 不同,则返回true

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

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

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

other 复制到此选项中,使两个选项完全相同。返回对QCoapOption 的引用。

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

如果QCoapOptionother 相等,则返回true

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