QCoapResource Class
QCoapResource 类保存了有关已发现资源的信息。更多内容...
| 头文件: | #include <QCoapResource> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Coap) target_link_libraries(mytarget PRIVATE Qt6::Coap) |
| qmake: | QT += coap |
注意:该类中的所有函数均为可重入函数。
公共函数
| QCoapResource() | |
| QCoapResource(const QCoapResource &other) | |
| ~QCoapResource() | |
| uint | contentFormat() const |
| QHostAddress | host() const |
| QString | interface() const |
| int | maximumSize() const |
| bool | observable() const |
| QString | path() const |
| QString | resourceType() const |
| void | setContentFormat(uint contentFormat) |
| void | setHost(const QHostAddress &host) |
| void | setInterface(const QString &interface) |
| void | setMaximumSize(int maximumSize) |
| void | setObservable(bool observable) |
| void | setPath(const QString &path) |
| void | setResourceType(const QString &resourceType) |
| void | setTitle(const QString &title) |
| void | swap(QCoapResource &other) |
| QString | title() const |
| QCoapResource & | operator=(const QCoapResource &other) |
详细说明
QCoapRequest 包含资源的路径和标题等数据以及其他辅助信息。
另请参阅 QCoapResourceDiscoveryReply 。
成员函数文档
QCoapResource::QCoapResource()
创建一个新的 QCoapResource 对象。
QCoapResource::QCoapResource(const QCoapResource &other)
创建一个新的 CoAP 资源,作为other 的副本,使这两个资源完全相同。
[noexcept] QCoapResource::~QCoapResource()
摧毁QCoapResource 。
uint QCoapResource::contentFormat() const
返回资源的 Content-Format 代码。
Content-Format 代码对应于“ct”属性,并提供了有关该资源返回的 Content-Formats 的提示。该规范在RFC 7252 中有明确说明。
另请参阅 setContentFormat()。
QHostAddress QCoapResource::host() const
返回资源的主机。
另请参阅 setHost()。
QString QCoapResource::interface() const
返回资源的接口描述。
接口描述的“if”属性是一个不透明字符串,用于提供名称或 URI,以指明用于与目标资源交互的特定接口定义。该属性在RFC 6690 中进行了规定。
另请参阅 setInterface()。
int QCoapResource::maximumSize() const
返回资源的最大大小。
最大大小估计属性“sz”用于指示通过对目标 URI 执行 GET 请求所返回的资源表示的最大大小。该属性在RFC 6690 中进行了规定。
另请参阅 setMaximumSize()。
bool QCoapResource::observable() const
如果资源是可观察的,则返回true
另请参阅 setObservable()。
QString QCoapResource::path() const
返回资源的路径。
另请参阅 setPath()。
QString QCoapResource::resourceType() const
返回资源的类型。
另请参阅 setResourceType()。
void QCoapResource::setContentFormat(uint contentFormat)
将资源的内容格式设置为contentFormat 。内容格式可以是CoAP内容格式注册表中定义的内容格式之一。
注意:CoAP 支持 XML、JSON 等常见内容格式,但这些格式基于文本,因此无论在有效载荷还是处理方面都较为繁重。推荐与 CoAP 配合使用的内容格式之一是 CBOR,该格式专为此类场景设计。
另请参阅 contentFormat()、QCborStreamWriter 以及QCborStreamReader 。
void QCoapResource::setHost(const QHostAddress &host)
将资源的主机设置为host 。
另请参阅 host()。
void QCoapResource::setInterface(const QString &interface)
将资源的接口设置为interface 。
另请参阅 interface()。
void QCoapResource::setMaximumSize(int maximumSize)
将资源的最大大小设置为maximumSize 。
另请参阅 maximumSize()。
void QCoapResource::setObservable(bool observable)
如果observable 参数的值为true ,则将该资源设为可观察对象。
另请参阅 observable()。
void QCoapResource::setPath(const QString &path)
将资源路径设置为path 。
另请参阅 path()。
void QCoapResource::setResourceType(const QString &resourceType)
将资源类型设置为resourceType 。
另请参阅 resourceType()。
void QCoapResource::setTitle(const QString &title)
将资源的标题设置为title 。
另请参阅 title()。
[noexcept] void QCoapResource::swap(QCoapResource &other)
将此资源与other 互换。此操作速度极快,且绝不会失败。
QString QCoapResource::title() const
返回资源的标题。
另请参阅 setTitle()。
QCoapResource &QCoapResource::operator=(const QCoapResource &other)
将other 复制到此资源中,使这两个资源完全一致。返回对此QCoapResource 的引用。
© 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.