Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Qt application sometimes is unable to connect to Internet?

$
0
0
Hi, 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. //Header File #ifndef CHECKUPDATES_H #define CHECKUPDATES_H   #include <QObject> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> #include <QTimer>   class CheckUpdates : public QObject {     Q_OBJECT public:     explicit CheckUpdates(bool *finish, QString *link);       void checkUpdates();     signals:     public slots:   private slots:     void fileDownloaded(QNetworkReply *reply);     void killChecking();   private:     QNetworkAccessManager manager;     QTimer timer;     bool *finished;     QString *url; };   #endif // CHECKUPDATES_H   //Source File #include "checkupdates.h" #include <QDebug>   CheckUpdates::CheckUpdates(bool *finish, QString *link) : QObject() {     finished = finish;     url = link; }   void CheckUpdates::fileDownloaded(QNetworkReply *reply) {     QString line = reply->readLine().simplified();     if(line.contains("Secret Keyword"))     {         //success!     }     else     {         qWarning("Failure checking Updates");         qDebug() << line << endl;         qDebug() << reply->readAll().simplified();         *url = "fail";     }       reply->deleteLater();     *finished = true; }   void CheckUpdates::killChecking() {     disconnect(&manager, 0, 0, 0);     disconnect(&timer, 0, 0, 0);     *finished = true; }   void CheckUpdates::checkUpdates() {     connect(&manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileDownloaded(QNetworkReply*)));     connect(&timer, SIGNAL(timeout()), this, SLOT(killChecking()));     QNetworkRequest request(QUrl("https://googledrive.com/host/funky_code_by_Google/myFile.html"));     manager.get(request);     timer.start(10000); } 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?

Viewing all articles
Browse latest Browse all 13965

Trending Articles