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 }
flags Features
enum class Reachability { Unknown, Disconnected, Local, Site, Online }


Public Functions

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


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::Feature
flags QNetworkInformation::Features

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

QNetworkInformation::Feature::Reachability0x1If the plugin supports this feature then the reachability property will be available. See also QNetworkInformation::Reachability.

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

enum class QNetworkInformation::Reachability

QNetworkInformation::Reachability::Unknown0If 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::Disconnected1Indicates that the system may have no connectivity at all.
QNetworkInformation::Reachability::Local2Indicates that the system is connected to a network, but it might only be able to access devices on the local network.
QNetworkInformation::Reachability::Site3Indicates 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::Online4Indicates that the system is connected to a network and able to access the Internet.

See also QNetworkInformation::reachability.

Property Documentation

[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.

© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.