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
qnetworkinformation.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKINFORMATION_H
6#define QNETWORKINFORMATION_H
7
8#include <QtNetwork/qtnetworkglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qstringview.h>
11#include <QtCore/qstringlist.h>
12
13QT_BEGIN_NAMESPACE
14
15class QNetworkInformationBackend;
18class Q_NETWORK_EXPORT QNetworkInformation : public QObject
19{
20 Q_OBJECT
21 Q_DECLARE_PRIVATE(QNetworkInformation)
22 Q_PROPERTY(Reachability reachability READ reachability NOTIFY reachabilityChanged)
23 Q_PROPERTY(bool isBehindCaptivePortal READ isBehindCaptivePortal
24 NOTIFY isBehindCaptivePortalChanged)
25 Q_PROPERTY(TransportMedium transportMedium READ transportMedium NOTIFY transportMediumChanged)
26 Q_PROPERTY(bool isMetered READ isMetered NOTIFY isMeteredChanged)
27 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
28public:
29 enum class Reachability {
30 Unknown,
31 Disconnected,
32 Local,
33 Site,
34 Online,
35 };
36 Q_ENUM(Reachability)
37
38 enum class TransportMedium {
39 Unknown,
40 Ethernet,
41 Cellular,
42 WiFi,
43 Bluetooth,
44 };
45 Q_ENUM(TransportMedium)
46
47 enum class Feature {
48 Reachability = 0x1,
49 CaptivePortal = 0x2,
50 TransportMedium = 0x4,
51 Metered = 0x8,
52 };
53 Q_DECLARE_FLAGS(Features, Feature)
54 Q_FLAG(Features)
55
56 Reachability reachability() const;
57
58 bool isBehindCaptivePortal() const;
59
60 TransportMedium transportMedium() const;
61
62 bool isMetered() const;
63
64 QString backendName() const;
65
66 bool supports(Features features) const;
67 Features supportedFeatures() const;
68
69 static bool loadDefaultBackend();
70 static bool loadBackendByName(QStringView backend);
71 static bool loadBackendByFeatures(Features features);
72#if QT_DEPRECATED_SINCE(6,4)
73 QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByName") static bool load(QStringView backend);
74 QT_DEPRECATED_VERSION_X_6_4("Use loadBackendByFeatures") static bool load(Features features);
75#endif
76 static QStringList availableBackends();
77 static QNetworkInformation *instance();
78
79Q_SIGNALS:
80 void reachabilityChanged(QNetworkInformation::Reachability newReachability);
81 void isBehindCaptivePortalChanged(bool state);
82 void transportMediumChanged(QNetworkInformation::TransportMedium current);
83 void isMeteredChanged(bool isMetered);
84
85private:
86 friend struct QNetworkInformationDeleter;
87 QNetworkInformation(QNetworkInformationBackend *backend);
88 ~QNetworkInformation() override;
89
90 Q_DISABLE_COPY_MOVE(QNetworkInformation)
91};
92
93Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkInformation::Features)
94
95QT_END_NAMESPACE
96
97#endif
static QNetworkInformation * create(QStringView name)
static QNetworkInformation * createDummy()
static void addToList(QNetworkInformationBackendFactory *factory)
static QNetworkInformation * instance()
static void removeFromList(QNetworkInformationBackendFactory *factory)
\inmodule QtNetwork
static void networkInfoCleanup()
Q_GLOBAL_STATIC(QStaticNetworkInformationDataHolder, dataHolder)
Q_GLOBAL_STATIC_WITH_ARGS(PermissionStatusHash, g_permissionStatusHash,({ { qMetaTypeId< QCameraPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QMicrophonePermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QBluetoothPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QContactsPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QCalendarPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QLocationPermission >(), Qt::PermissionStatus::Undetermined } }))
void operator()(QNetworkInformation *information)