QNetworkReply - Strange error in enum, OperationCanceled instead of Timeout?

103 Views Asked by At

My API server is turned off and i run following code. I dont understand why QNetworkReply::OperationCanceledError error enum is returned instead of QNetworkReply::TimeoutError. What is wrong? Am i doing something wrong or is it Qt bug?

From documentation that error should be if "the operation was canceled via calls to abort() or close() before it was finished." I see no reason for that.

QByteArray encodedData = data.toUtf8();
QUrl url("http://myapi/jsonrpc");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");

QNetworkAccessManager manager;
manager.setTransferTimeout(500);
QNetworkReply* reply = manager.post(request, encodedData);

QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();

if (reply->error() != QNetworkReply::NoError) {
    QString errorMsg = QString("HTTP Network request has failed. Code: ") + QVariant::fromValue(reply->error()).toString();
    delete reply;
    // error
    // here i got QNetworkReply::OperationCanceledError
}

QByteArray response = reply->readAll();
//ok
0

There are 0 best solutions below