[Solved] Qt application sometimes is unable to connect to Internet?
In my application I have provided functionality to check for updates. This is done by reading an html file hosted on Google servers. This code works on some hardware while on some it just does not work. Probably because of Firewall or bad Anti-virus. But I am not sure what is the reason. So I wanted to know whether Qt provides any functionality to check why connection to the Internet is not happening? Probably an error message would do. Here is my code. I found it on one of the Wiki's but cannot remember the link.
class CheckUpdates : public QObject
explicit CheckUpdates(bool *finish, QString *link);
void fileDownloaded(QNetworkReply *reply);
#endif // CHECKUPDATES_H
CheckUpdates::CheckUpdates(bool *finish, QString *link) : QObject()
finished = finish;
url = link;
void CheckUpdates::fileDownloaded(QNetworkReply *reply)
QString line = reply->readLine().simplified();
qWarning("Failure checking Updates");
qDebug() << line << endl;
qDebug() << reply->readAll().simplified();
*url = "fail";
reply->deleteLater(); *finished = true;
disconnect(&manager, 0, 0, 0);
disconnect(&timer, 0, 0, 0);
*finished = true;
connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileDownloaded(QNetworkReply*)));
connect(&timer, SIGNAL(timeout()), this, SLOT(killChecking()));
On some PC's this is working just fine, while on some the request gets killed by the timer. The strange thing is that the qWarning() is not getting thrown! Why is this strange stuff happening?
To check an error message use reply->error().
qWarning is not called because fileDownloaded never gets called most likely.
Thanks for your reply. I will check error() and it in my code.
But can you please tell me why fileDownloaded() does not get called?
It cannot be that connection is not happening because it would throw a qWarning() internally. But since there is no such warning the connection must be happening.
When the timer runs out you're disconnecting from QNetworkAccessManager::finished() signal which would call fileDownloaded should the connection actually finish.
so should I refrain from using such a timer?
But if I remove the timer, is it guaranteed that fileDownloaded() would be called eventually.
Also if this is called after a fixed time interval then is it possible to set this time interval?
So that I would no longer be needing the timer then.
I don't think it's possible to set the timeout in the manager I think you'd be waitnig forever for the connection to timeout.