QCoapReply Class
QCoapReply 类用于存储 CoAP 响应的数据。更多内容...
| 头文件: | #include <QCoapReply> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Coap) target_link_libraries(mytarget PRIVATE Qt6::Coap) |
| qmake: | QT += coap |
| 继承自: | QIODevice |
| 被继承者: |
注:该类中的所有函数均为可重入的。
公共函数
| virtual | ~QCoapReply() override |
| void | abortRequest() |
| QtCoap::Error | errorReceived() const |
| bool | isAborted() const |
| bool | isFinished() const |
| bool | isRunning() const |
| bool | isSuccessful() const |
| QCoapMessage | message() const |
| QtCoap::Method | method() const |
| QCoapRequest | request() const |
| QtCoap::ResponseCode | responseCode() const |
| QUrl | url() const |
信号
| void | aborted(const QCoapToken &token) |
| void | error(QCoapReply *reply, QtCoap::Error error) |
| void | finished(QCoapReply *reply) |
| void | notified(QCoapReply *reply, const QCoapMessage &message) |
详细说明
QCoapReply 包含与使用QCoapClient 发送的请求相关的数据。
当响应完全接收完毕或请求失败时,会发出finished()信号。
特别是对于Observe请求,每当收到通知时,都会触发notified() 信号。
另请参阅 QCoapClient 、QCoapRequest 和QCoapResourceDiscoveryReply 。
成员函数文档
[override virtual noexcept] QCoapReply::~QCoapReply()
如果尚未收到该请求的响应,则销毁该QCoapReply 并中止该请求。
void QCoapReply::abortRequest()
如果请求尚未完成,则立即中止该请求,并发出aborted (const QCoapToken &token)信号。
[signal] void QCoapReply::aborted(const QCoapToken &token)
当请求被中止或响应被删除时,会发出此信号。其token 参数是已被中止的交换的令牌。
注意:如果 QCoapReply 在未完成时被删除,则在QCoapReply 被销毁之前,将立即发出aborted()和finished()两个信号。鉴于QCoapReply 在接收信号时可能已被删除,您不应依赖sender()对象仍然有效。
[signal] void QCoapReply::error(QCoapReply *reply, QtCoap::Error error)
每当发生错误时,都会发出此信号,随后会发出finished()信号。
出于方便起见,其reply 参数即为QCoapReply 本身,而error 参数则是接收到的错误。
QtCoap::Error QCoapReply::errorReceived() const
返回响应中的错误,若无错误,则返回 QCoapReply::NoError。
[signal] void QCoapReply::finished(QCoapReply *reply)
每当相应的请求完成时,无论是否成功,都会发出此信号。当观察某个资源时,此信号仅在观察结束时发出一次。
出于方便起见,reply 参数即为QCoapReply 本身。
注意:如果在 观察未完成时删除了QCoapReply ,那么在QCoapReply 被销毁之前,aborted()和finished()信号都会立即被触发。鉴于QCoapReply 在接收到信号时可能已被删除,您不应依赖reply 仍然有效。
另请参阅 QCoapClient::finished()、isFinished()、notified() 和aborted()。
bool QCoapReply::isAborted() const
如果请求已被中止,则返回true 。
bool QCoapReply::isFinished() const
如果请求已完成,则返回 `true `。
另请参阅 finished()。
bool QCoapReply::isRunning() const
如果请求正在运行,则返回true 。
bool QCoapReply::isSuccessful() const
如果请求正常完成且未出现错误,则返回true 。
QCoapMessage QCoapReply::message() const
返回所包含的消息。
QtCoap::Method QCoapReply::method() const
返回关联请求的方法。
[signal] void QCoapReply::notified(QCoapReply *reply, const QCoapMessage &message)
每当从被监视的资源收到通知时,都会发出此信号。
其message 参数是一个QCoapMessage ,其中包含有效载荷和消息详细信息。出于方便考虑,reply 参数即为QCoapReply 本身。
另请参阅 QCoapClient::finished()、isFinished()、finished() 和aborted()。
QCoapRequest QCoapReply::request() const
返回相关的请求。
QtCoap::ResponseCode QCoapReply::responseCode() const
返回该请求的响应代码。
QUrl QCoapReply::url() const
返回相关请求的目标 URI。
© 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.