Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_network_kernel_qnetworkinformation.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//![file]
5#include <QCoreApplication>
6#include <QNetworkInformation>
7#include <QDebug>
8
9void onReachabilityChanged(QNetworkInformation::Reachability reachability) {
10 switch (reachability) {
11 case QNetworkInformation::Reachability::Unknown:
12 qDebug() << "Network reachability is unknown.";
13 break;
14 case QNetworkInformation::Reachability::Disconnected:
15 qDebug() << "Network is disconnected.";
16 break;
17 case QNetworkInformation::Reachability::Local:
18 qDebug() << "Network is locally reachable.";
19 break;
20 case QNetworkInformation::Reachability::Site:
21 qDebug() << "Network can reach the site.";
22 break;
23 case QNetworkInformation::Reachability::Online:
24 qDebug() << "Network is online.";
25 break;
26 }
27}
28
29int main(int argc, char *argv[]) {
30 QCoreApplication a(argc, argv);
31
32 // Check if QNetworkInformation is supported
33 if (!QNetworkInformation::loadDefaultBackend()) {
34 qWarning() << "QNetworkInformation is not supported on this platform or backend.";
35 return 1;
36 }
37
38 QNetworkInformation* netInfo = QNetworkInformation::instance();
39
40 // Connect to the reachabilityChanged signal
41 QObject::connect(netInfo, &QNetworkInformation::reachabilityChanged,
42 &onReachabilityChanged);
43
44 // Print initial status
45 onReachabilityChanged(netInfo->reachability());
46
47 return a.exec();
48}
49//![file]
int main(int argc, char *argv[])
[ctor_close]
void onReachabilityChanged(QNetworkInformation::Reachability reachability)
[file]