I'm trying to load some data with QNetworkAccessManager. The problem is that if my server doesn't respond, is down or something the QNetworkAccessManager::finished() signal never emit neither does the QNetworkReply::error(QNetworkReply::NetworkError). Can I set some kind of timeout so if the server doesn't responed I get an error? I haven't find a way to se the timeout, where can I do that? Or am I doing something wrong?

Qt Code:
  1. void MyWidget::load() {
  2. QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager(this);
  3. connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(slotFinished(QNetworkReply*)));
  4. QUrl url("http://www.domain.com"); //A domain that will not respond and will timeout
  5. QNetworkReply *reply = networkAccessManager->get(QNetworkRequest(url));
  6. connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(slotError( QNetworkReply::NetworkError)));
  7. }
  8.  
  9. void MyWidget::slotError(QNetworkReply::NetworkError) {
  10. ui.textEdit->setText("error");
  11. }
  12.  
  13. void MyWidget::slotFinished(QNetworkReply* reply) {
  14. ui.textEdit->setText("reply");
  15. }
To copy to clipboard, switch view to plain text mode