diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-05-23 15:37:21 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-05-23 15:39:27 +0200 |
commit | d2744ade327fe6b63bb80d6acd9c1cd7ae6e317f (patch) | |
tree | b39a74a4fa41e0ac8da9a95e3acfaf5691b318a4 /src/coap/qcoapclient.cpp | |
parent | fd94d8e5673a5d5228aa2d38b605fde7a881332b (diff) |
Remove QCoapClien's constructor for specifying a custom connection
Change-Id: I5b51c71ab11cbce5755a69c58f34bfa5e7cd5385
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/coap/qcoapclient.cpp')
-rw-r--r-- | src/coap/qcoapclient.cpp | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp index 5469ef2..4ff4ced 100644 --- a/src/coap/qcoapclient.cpp +++ b/src/coap/qcoapclient.cpp @@ -162,16 +162,8 @@ QCoapClientPrivate::~QCoapClientPrivate() constructors. */ QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode, QObject *parent) : - QCoapClient(new QCoapQUdpConnection(securityMode), parent) -{ -} - -/*! - Constructs a QCoapClient object with the given \a connection and - sets \a parent as the parent object. -*/ -QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) : - QObject(*new QCoapClientPrivate(new QCoapProtocol, connection), parent) + QObject(*new QCoapClientPrivate(new QCoapProtocol, new QCoapQUdpConnection(securityMode)), + parent) { Q_D(QCoapClient); @@ -210,6 +202,28 @@ QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) : } /*! + \internal + + Sets the client's connection to \a customConnection. +*/ +void QCoapClientPrivate::setConnection(QCoapConnection *customConnection) +{ + Q_Q(QCoapClient); + + delete connection; + connection = customConnection; + + q->connect(connection, &QCoapConnection::readyRead, protocol, + [this](const QByteArray &data, const QHostAddress &sender) { + protocol->d_func()->onFrameReceived(data, sender); + }); + q->connect(connection, &QCoapConnection::error, protocol, + [this](QAbstractSocket::SocketError socketError) { + protocol->d_func()->onConnectionError(socketError); + }); +} + +/*! Destroys the QCoapClient object and frees up any resources. Note that QCoapReply objects that are returned from this class have the QCoapClient set as their parents, which means that |