- class QNetworkInformation#
QNetworkInformation
exposes various network information through native backends. More…Synopsis#
Properties#
isBehindCaptivePortalᅟ
- Lets you know if the user’s device is behind a captive portalisMeteredᅟ
- Check if the current connection is meteredreachabilityᅟ
- Current state of the system’s network connectivitytransportMediumᅟ
- Currently active transport medium for the application
Methods#
def
backendName()
def
isMetered()
def
reachability()
def
supports()
Signals#
Static functions#
def
instance()
def
load()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
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
- class Reachability#
Constant
Description
QNetworkInformation.Reachability.Unknown
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
Indicates that the system may have no connectivity at all.
QNetworkInformation.Reachability.Local
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
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
Indicates that the system is connected to a network and able to access the Internet.
See also
- class TransportMedium#
Lists the currently recognized media with which one can connect to the internet.
Constant
Description
QNetworkInformation.TransportMedium.Unknown
Returned if either the OS reports no active medium, the active medium is not recognized by Qt, or the TransportMedium feature is not supported.
QNetworkInformation.TransportMedium.Ethernet
Indicates that the currently active connection is using ethernet. Note: This value may also be returned when Windows is connected to a Bluetooth personal area network.
QNetworkInformation.TransportMedium.Cellular
Indicates that the currently active connection is using a cellular network.
QNetworkInformation.TransportMedium.WiFi
Indicates that the currently active connection is using Wi-Fi.
QNetworkInformation.TransportMedium.Bluetooth
Indicates that the currently active connection is connected using Bluetooth.
See also
New in version 6.3.
- class Feature#
(inherits
enum.Flag
) Lists all of the features that a plugin may currently support. This can be used in QNetworkInformation::load().Constant
Description
QNetworkInformation.Feature.Reachability
If the plugin supports this feature then the
reachability
property will provide useful results. Otherwise it will always returnReachability::Unknown
. See alsoReachability
.QNetworkInformation.Feature.CaptivePortal
If the plugin supports this feature then the
isBehindCaptivePortal
property will provide useful results. Otherwise it will always returnfalse
.QNetworkInformation.Feature.TransportMedium
If the plugin supports this feature then the
transportMedium
property will provide useful results. Otherwise it will always returnTransportMedium::Unknown
. See alsoTransportMedium
.QNetworkInformation.Feature.Metered
If the plugin supports this feature then the
isMetered
property will provide useful results. Otherwise it will always returnfalse
.
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property isBehindCaptivePortalᅟ: bool#
This property holds 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
.- Access functions:
- property isMeteredᅟ: bool#
This property holds Check if the current connection is metered.
This property returns whether the current connection is (known to be) metered or not. You can use this as a guiding factor to decide whether your application should perform certain network requests or uploads. For instance, you may not want to upload logs or diagnostics while this property is
true
.- Access functions:
Signal
isMeteredChanged()
- property reachabilityᅟ: QNetworkInformation.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:
- property transportMediumᅟ: QNetworkInformation.TransportMedium#
This property holds The currently active transport medium for the application.
This property returns the currently active transport medium for the application, on operating systems where such information is available.
When the current transport medium changes a signal is emitted, this can, for instance, occur when a user leaves the range of a
WiFi
network, unplugs their ethernet cable or enables Airplane mode.- Access functions:
- static availableBackends()#
- Return type:
list of strings
Returns a list of the names of all currently available backends.
- backendName()#
- Return type:
str
Returns the name of the currently loaded backend.
- static instance()#
- Return type:
Returns a pointer to the instance of the
QNetworkInformation
, if any.See also
- isBehindCaptivePortal()#
- Return type:
bool
Getter of property
isBehindCaptivePortalᅟ
.- isBehindCaptivePortalChanged(state)#
- Parameters:
state – bool
Notification signal of property
isBehindCaptivePortalᅟ
.- isMetered()#
- Return type:
bool
Getter of property
isMeteredᅟ
.- isMeteredChanged(isMetered)#
- Parameters:
isMetered – bool
Notification signal of property
isMeteredᅟ
.- static load(features)#
- Parameters:
features – Combination of
Feature
- Return type:
bool
Note
This function is deprecated.
Use
loadBackendByFeatures()
instead.- static load(backend)
- Parameters:
backend – str
- Return type:
bool
Note
This function is deprecated.
Use
loadBackendByName()
instead.- static loadBackendByFeatures(features)#
- Parameters:
features – Combination of
Feature
- Return type:
bool
Load a backend which supports
features
.Returns
true
if it managed to load the requested backend or if it was already loaded. Returnsfalse
otherwise.See also
- static loadBackendByName(backend)#
- Parameters:
backend – str
- Return type:
bool
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. Returnsfalse
otherwise.See also
- static loadDefaultBackend()#
- Return type:
bool
Attempts to load the platform-default backend.
Note
Starting with 6.7 this tries to load any backend that supports
Reachability
if the platform-default backend is not available or fails to load. If this also fails it will fall back to a backend that only returns the default values for all properties.This platform-to-plugin mapping is as follows:
Platform
Plugin-name
Windows
networklistmanager
Apple (macOS/iOS)
scnetworkreachability
Android
android
Linux
networkmanager
This function is provided for convenience where the logic earlier is good enough. If you require a specific plugin then you should call
loadBackendByName()
orloadBackendByFeatures()
directly instead.Determines a suitable backend to load and returns
true
if this backend is already loaded or on successful loading of it. Returnsfalse
if any other backend has already been loaded, or if loading of the selected backend fails.See also
- reachability()#
- Return type:
Getter of property
reachabilityᅟ
.- reachabilityChanged(newReachability)#
- Parameters:
newReachability –
Reachability
Notification signal of property
reachabilityᅟ
.Returns all the supported features of the current backend.
Returns
true
if the currently loaded backend supportsfeatures
.- transportMedium()#
- Return type:
Getter of property
transportMediumᅟ
.- transportMediumChanged(current)#
- Parameters:
current –
TransportMedium
Notification signal of property
transportMediumᅟ
.