View Full Version : How my software can catch/avoid "No carrier" response from QNetwork?

14th March 2019, 20:37

I'm facing a problem when I need to treat some asynchronous requisitions from a service.

networkManager = new QNetworkAccessManager(this);
QNetworkRequest request((QUrl (url)));
request.setHeader(QNetworkRequest::ContentTypeHead er, "application/json");
request.setRawHeader("Cache-Control", "no-cache");
reply = networkManager->post(request, QJsonDocument(body).toJson());
reply = networkManager->get(request);

QObject::connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(replyError(QNetworkReply::NetworkError)));

Undesirable behavior occurs in situations where network access service is unstable. If the requisition fails, I can handle that and abort the reply. However, sometimes the long latency in response can result in a "long pooling" ways of QNetworkReply that waits for a long time, generating after x seconds the "No carrier" message.

It's very important to avoid this behavior, trying to catch "No carrier" or with the use of some approach to abort the reply.

The collateral effects are related to issues in QML interactions and the application can stop working in the worst case because several requests are made for each minute and QNetworkReply allocate each time more threads.

Mar 14 10:57:49 qt application[12911]: "No carrier"
Mar 14 10:57:59 qt application[12911]: "No carrier"
Mar 14 11:09:29 qt application[12911]: "No carrier"
Mar 14 11:09:39 qt application[12911]: "No carrier"
Mar 14 11:09:49 qt application[12911]: "No carrier"
Mar 14 11:36:30 qt application[12911]: "No carrier"
How I could do to fix that?

Added after 48 minutes:

I found an approach and it worked very well.

Set a timer to the reply is a way to deal with this question. A detailed discussion can be found here: