t-mon / qtcoap

Constrained Application Protocol (CoAP) library written in Qt.
GNU General Public License v3.0
6 stars 5 forks source link

Error: Unknown reply received: Please report a bug if you get this message #3

Open taimooralam opened 7 years ago

taimooralam commented 7 years ago

The Core::onReplyFinished(CoapReply *reply) finished method does not recognize one of the replies of a get request and instead executes the last else of the method. What might be the problem here?

} else if (reply == m_reply) { // the get request should execute this 
    //qDebug() << "------------------------------------------" << endl << reply;

    QString path = reply->request().url().path();

    QString payload = reply->payload();

} else { //but instead executes part

    qWarning() << "Unknown reply received: Please report a bug if you get this message";

}
t-mon commented 7 years ago

Hard to say without the whole code. You could try to use a lambda function like this (if you use at least c++11):

    CoapReply *reply = m_coap->get(CoapRequest(url));
    connect(reply, &CoapReply::finished, [reply]() {
        if (reply->error() != CoapReply::NoError) {
            qWarning() << "Could not get resource" << reply->request().url().toString() << ":" << reply->errorString();
            reply->deleteLater();
            return;
        }

        qDebug() << reply->payload();
        // Do something
        reply->deleteLater();
    });