File indexing completed on 2024-07-14 15:39:38

0001 /*
0002  *   Copyright (C) 2016 by Aditya Mehra <aix.m@outlook.com>                      *
0003  *   This program is free software; you can redistribute it and/or modify
0004  *   it under the terms of the GNU Library General Public License as
0005  *   published by the Free Software Foundation; either version 2, or
0006  *   (at your option) any later version.
0007  *
0008  *   This program is distributed in the hope that it will be useful,
0009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0011  *   GNU General Public License for more details
0012  *
0013  *   You should have received a copy of the GNU Library General Public
0014  *   License along with this program; if not, write to the
0015  *   Free Software Foundation, Inc.,
0016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0017  */
0018 
0019 #include "connectioncheck.h"
0020 
0021 #include <QtNetwork>
0022 
0023 ConnectionCheck::ConnectionCheck(QObject *parent)
0024     : QObject(parent)
0025 {
0026 }
0027 
0028 bool ConnectionCheck::checkConnection(){
0029     QNetworkAccessManager nam;
0030     QNetworkRequest req(QUrl("http://www.example.com/"));
0031     QNetworkReply *reply = nam.get(req);
0032     QEventLoop loop;
0033     connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
0034     loop.exec();
0035     if(reply->bytesAvailable()) {
0036         return true;
0037     }
0038     else { 
0039         return false;
0040     }
0041 }