How to do a request with timeout using QNetworkAccessManager and QNetworkRequest API?
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
QNetworkReply *reply= nam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
I would assume that you check with the "error method":http://qt-project.org/doc/qt-4.8/qnetworkreply.html#error for a time-out. Also you may connect to the "error signal.":http://qt-project.org/doc/qt-4.8/qnetworkreply.html#error-2
Thank you! That error signal is very useful for me now, but the request have a great delay to trigger the error signal. And how i define the maximum timeout for request?
You could manually start a QTimer at the same time you make your initial request, which would trigger the "timeout" handling if it is allowed to expire. Then in the slot which handles the finished() signal, you can stop the timer so it never has a chance to expire when things work as expected.