QNetworkInformation Class

QNetworkInformation exposes various network information through native backends. 更多...

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

公共类型

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

特性

公共函数

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

信号

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

静态公共成员

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

详细描述

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.

另请参阅 QNetworkInformation::Feature .

成员类型文档编制

enum class QNetworkInformation:: Feature
flags QNetworkInformation:: 特征

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

常量 描述
QNetworkInformation::Feature::Reachability 0x1 If the plugin supports this feature then the reachability property will be available. See also QNetworkInformation::Reachability .
QNetworkInformation::Feature::CaptivePortal 0x2 If the plugin supports this feature then the isBehindCaptivePortal property will be available.

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

enum class QNetworkInformation:: Reachability

常量 描述
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.

另请参阅 QNetworkInformation::reachability .

特性文档编制

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

该特性在 Qt 6.2 引入。

访问函数:

bool isBehindCaptivePortal () const

通知程序信号:

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.

访问函数:

QNetworkInformation::Reachability reachability () const

通知程序信号:

void reachabilityChanged (QNetworkInformation::Reachability newReachability )

成员函数文档编制

[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 ,若有的话。

另请参阅 load ().

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

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

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

另请参阅 instance .

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

Load a backend which supports features .

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

另请参阅 instance .

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

返回 true if the currently loaded backend supports features .