Changeset View
Changeset View
Standalone View
Standalone View
plugin/connectioncheck.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2016 by Aditya Mehra <aix.m@outlook.com> * | ||||
3 | * This program is free software; you can redistribute it and/or modify | ||||
4 | * it under the terms of the GNU Library General Public License as | ||||
5 | * published by the Free Software Foundation; either version 2, or | ||||
6 | * (at your option) any later version. | ||||
7 | * | ||||
8 | * This program is distributed in the hope that it will be useful, | ||||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
11 | * GNU General Public License for more details | ||||
12 | * | ||||
13 | * You should have received a copy of the GNU Library General Public | ||||
14 | * License along with this program; if not, write to the | ||||
15 | * Free Software Foundation, Inc., | ||||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "connectioncheck.h" | ||||
20 | | ||||
21 | #include <QtNetwork> | ||||
22 | | ||||
23 | ConnectionCheck::ConnectionCheck(QObject *parent) | ||||
24 | : QObject(parent) | ||||
25 | { | ||||
26 | } | ||||
27 | | ||||
28 | bool ConnectionCheck::checkConnection(){ | ||||
29 | QNetworkAccessManager nam; | ||||
30 | QNetworkRequest req(QUrl("http://www.example.com/")); | ||||
31 | QNetworkReply *reply = nam.get(req); | ||||
32 | QEventLoop loop; | ||||
33 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); | ||||
34 | loop.exec(); | ||||
35 | if(reply->bytesAvailable()) { | ||||
36 | return true; | ||||
37 | } | ||||
38 | else { | ||||
39 | return false; | ||||
40 | } | ||||
41 | } |