QNetworkAccessManager timeout
-
Hi guys,
How to do a request with timeout using QNetworkAccessManager and QNetworkRequest API?
@
QNetworkAccessManager *nam = new QNetworkAccessManager(this);
QString url("http://myhost.com.br");
QNetworkReply *reply= nam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
loop.exec();
@Thanks!
-
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
-
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.