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 () 再次。
另请参阅 QNetworkInformation::Feature .
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.
常量 | 值 | 描述 |
---|---|---|
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.
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 .
返回
true
if the currently loaded backend supports
features
.