QCoapClient Class▲
-
Header: QCoapClient
-
qmake: QT += coap
-
Inherits: QObject
Detailed Description▲
The QCoapClient class contains signals that get triggered when the reply of a sent request has arrived.
The application can use a QCoapClient to send requests over a CoAP network. It provides functions for standard requests: each returns a QCoapReply object, to which the response data shall be delivered; this can be read when the finished() signal arrives.
A simple request can be sent with:
QCoapClient *
client =
new
QCoapClient(this
);
connect(client, &
amp;QCoapClient::
finished, this
, &
amp;TestClass::
slotFinished);
client-&
gt;get(QCoapRequest(Qurl("coap://coap.me/test"
)));
After processing of the request has finished, it is the responsibility of the user to delete the QCoapReply object at an appropriate time. Do not directly delete it inside the slot connected to finished(). You can use the deleteLater() function.
You can also use an observe request. This can be used as above, or more conveniently with the QCoapReply::notified() signal:
QCoapRequest request =
QCoapRequest(Qurl("coap://coap.me/obs"
));
QCoapReply *
reply =
client-&
gt;observe(request);
connect(reply, &
amp;QCoapReply::
notified, this
, &
amp;TestClass::
slotNotified);
And the observation can be cancelled with:
client-&
gt;cancelObserve(reply);
When a reply arrives, the QCoapClient emits a finished() signal.
For a discovery request, the returned object is a QCoapResourceDiscoveryReply. It can be used the same way as a QCoapReply but contains also a list of resources.
See Also▲
See also QCoapRequest, QCoapReply, QCoapResourceDiscoveryReply
Member Function Documentation▲
[explicit] QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode = QtCoap::SecurityMode::NoSecurity, QObject *parent = nullptr)▲
Constructs a QCoapClient object for the given securityMode and sets parent as the parent object.
The default for securityMode is QtCoap::NoSecurity, which disables security.
This connects using a QCoapQUdpConnection; to use a custom transport, sub-class QCoapConnection and pass an instance to one of the other constructors.