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?
void MyWidget::load() {
QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager(this);
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(slotFinished(QNetworkReply*)));
QUrl url
("http://www.domain.com");
//A domain that will not respond and will timeout QNetworkReply *reply = networkAccessManager->get(QNetworkRequest(url));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(slotError( QNetworkReply::NetworkError)));
}
void MyWidget::slotError(QNetworkReply::NetworkError) {
ui.textEdit->setText("error");
}
void MyWidget::slotFinished(QNetworkReply* reply) {
ui.textEdit->setText("reply");
}
void MyWidget::load() {
QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager(this);
connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(slotFinished(QNetworkReply*)));
QUrl url("http://www.domain.com"); //A domain that will not respond and will timeout
QNetworkReply *reply = networkAccessManager->get(QNetworkRequest(url));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(slotError( QNetworkReply::NetworkError)));
}
void MyWidget::slotError(QNetworkReply::NetworkError) {
ui.textEdit->setText("error");
}
void MyWidget::slotFinished(QNetworkReply* reply) {
ui.textEdit->setText("reply");
}
To copy to clipboard, switch view to plain text mode
Bookmarks