W3cubDocs

/Qt

QNetworkInformation Class

QNetworkInformation exposes various network information through native backends. More...

Header: #include <QNetworkInformation>
CMake: find_package(Qt6 COMPONENTS Network REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Network)
qmake: QT += network
Since: Qt 6.1
Inherits: QObject

Public Types

enum class Feature { Reachability, CaptivePortal }
flags Features
enum class Reachability { Unknown, Disconnected, Local, Site, Online }

Properties

Public Functions

QString backendName() const
bool isBehindCaptivePortal() const
QNetworkInformation::Reachability reachability() const
bool supports(QNetworkInformation::Features features) const

Signals

void isBehindCaptivePortalChanged(bool state)
void reachabilityChanged(QNetworkInformation::Reachability newReachability)

Static Public Members

QStringList availableBackends()
QNetworkInformation * instance()
bool load(QStringView backend)
bool load(QNetworkInformation::Features features)

Detailed Description

QNetworkInformation provides a cross-platform interface to network-related information through plugins.

Various plugins can have various functionality supported, and so you can load() plugins based on which features are needed.

QNetworkInformation is a singleton and stays alive from the first successful load() until destruction of the QCoreApplication object. If you destroy and re-create the QCoreApplication object you must call load() again.

See also QNetworkInformation::Feature.

Member Type Documentation

enum class QNetworkInformation::Featureflags QNetworkInformation::Features

Lists all of the features that a plugin may currently support. This can be used in QNetworkInformation::load().

Constant Value Description
QNetworkInformation::Feature::Reachability 0x1 If the plugin supports this feature then the reachability property will provide useful results. Otherwise it will always return Reachability::Unknown. See also QNetworkInformation::Reachability.
QNetworkInformation::Feature::CaptivePortal 0x2 If the plugin supports this feature then the isBehindCaptivePortal property will provide useful results. Otherwise it will always return false.

The Features type is a typedef for QFlags<Feature>. It stores an OR combination of Feature values.

enum class QNetworkInformation::Reachability

Constant Value Description
QNetworkInformation::Reachability::Unknown 0 If this value is returned then we may be connected but the OS has still not confirmed full connectivity, or this feature is not supported.
QNetworkInformation::Reachability::Disconnected 1 Indicates that the system may have no connectivity at all.
QNetworkInformation::Reachability::Local 2 Indicates that the system is connected to a network, but it might only be able to access devices on the local network.
QNetworkInformation::Reachability::Site 3 Indicates that the system is connected to a network, but it might only be able to access devices on the local subnet or an intranet.
QNetworkInformation::Reachability::Online 4 Indicates that the system is connected to a network and able to access the Internet.

See also QNetworkInformation::reachability.

Property Documentation

[read-only, since 6.2] isBehindCaptivePortal : const bool

Lets you know if the user's device is behind a captive portal.

This property indicates if the user's device is currently known to be behind a captive portal. This functionality relies on the operating system's detection of captive portals and is not supported on systems that don't report this. On systems where this is not supported this will always return false.

This property was introduced in Qt 6.2.

Access functions:

bool isBehindCaptivePortal() const

Notifier signal:

void isBehindCaptivePortalChanged(bool state)

[read-only] reachability : const Reachability

This property holds the current state of the system's network connectivity.

Indicates the level of connectivity that can be expected. Do note that this is only based on what the plugin/operating system reports. In certain scenarios this is known to be wrong. For example, on Windows the 'Online' check, by default, is performed by Windows connecting to a Microsoft-owned server. If this server is for any reason blocked then it will assume it does not have Online reachability. Because of this you should not use this as a pre-check before attempting to make a connection.

Access functions:

QNetworkInformation::Reachability reachability() const

Notifier signal:

void reachabilityChanged(QNetworkInformation::Reachability newReachability)

Member Function Documentation

[static] QStringList QNetworkInformation::availableBackends()

Returns a list of the names of all currently available backends.

QString QNetworkInformation::backendName() const

Returns the name of the currently loaded backend.

[static] QNetworkInformation *QNetworkInformation::instance()

Returns a pointer to the instance of the QNetworkInformation, if any.

See also load().

[static] bool QNetworkInformation::load(QStringView backend)

Attempts to load a backend whose name matches backend (case insensitively).

Returns true if it managed to load the requested backend or if it was already loaded. Returns false otherwise

See also instance.

[static] bool QNetworkInformation::load(QNetworkInformation::Features features)

Load a backend which supports features.

Returns true if it managed to load the requested backend or if it was already loaded. Returns false otherwise

See also instance.

bool QNetworkInformation::supports(QNetworkInformation::Features features) const

Returns true if the currently loaded backend supports features.

© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.2/qnetworkinformation.html