CSDN话题挑战赛第2期

1.详细描述

QNetworkConfigurationManager类管理着系统所提供的网络配置。

QNetworkConfigurationManager提供了对系统已知的网络配置的访问，使应用程序能够在运行时检测系统的能力（关于网络会话）。

defaultConfiguration()可以在打算立即创建一个新的网络会话而不关心特定的配置时使用。它返回一个QNetworkConfiguration::Discovered配置。如果没有任何发现的配置，则返回无效的配置。

2.成员类型说明

enum QNetworkConfigurationManager::Capability flags QNetworkConfigurationManager::Capabilities

ConstantValueDescription
QNetworkConfigurationManager::CanStartAndStopInterfaces0x00000001Network sessions and their underlying access points can be started and stopped. If this flag is not set QNetworkSession can only monitor but not influence the state of access points. On some platforms this feature may require elevated user permissions. This option is platform specific and may not always be available.
QNetworkConfigurationManager::DirectConnectionRouting0x00000002Network sessions and their sockets can be bound to a particular network interface. Any packet that passes through the socket goes to the specified network interface and thus disregards standard routing table entries. This may be useful when two interfaces can reach overlapping IP ranges or an application has specific needs in regards to target networks. This option is platform specific and may not always be available.
QNetworkConfigurationManager::SystemSessionSupport0x00000004If this flag is set the underlying platform ensures that a network interface is not shut down until the last network session has been closed(). This works across multiple processes. If the platform session support is missing this API can only ensure the above behavior for network sessions within the same process. In general mobile platforms have such support whereas most desktop platform lack this capability.
QNetworkConfigurationManager::ApplicationLevelRoaming0x00000008The system gives applications control over the systems roaming behavior. Applications can initiate roaming (in case the current link is not suitable) and are consulted if the system has identified a more suitable access point.
QNetworkConfigurationManager::ForcedRoaming0x00000010The system disconnects an existing access point and reconnects via a more suitable one. The application does not have any control over this process and has to reconnect its active sockets.
QNetworkConfigurationManager::DataStatistics0x00000020If this flag is set QNetworkSession can provide statistics about transmitted and received data.
QNetworkConfigurationManager::NetworkSessionRequired0x00000040If this flag is set the platform requires that a network session is created before network operations can be performed.

Capabilities类型是QFlags<Capability>的一个类型定义。它存储了Capability值的OR组合。

3.成员函数

QNetworkConfigurationManager::QNetworkConfigurationManager(QObject parent* = Q_NULLPTR)**

[virtual] QNetworkConfigurationManager::~QNetworkConfigurationManager()

QList<QNetworkConfiguration> QNetworkConfigurationManager::allConfigurations(QNetworkConfiguration::StateFlags filter = QNetworkConfiguration::StateFlags()) const

QNetworkConfigurationManager::Capabilities QNetworkConfigurationManager::capabilities() const

[signal] void QNetworkConfigurationManager::configurationChanged(const QNetworkConfiguration &config)

QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString &identifier) const

[signal] void QNetworkConfigurationManager::configurationRemoved(const QNetworkConfiguration &config)

QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const

bool QNetworkConfigurationManager::isOnline() const

```​
QNetworkConfigurationManager mgr;
QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations(QNetworkConfiguration::Active);
if (activeConfigs.count() > 0)
Q_ASSERT(mgr.isOnline());
else
Q_ASSERT(!mgr.isOnline());
​```

[signal] void QNetworkConfigurationManager::onlineStateChanged(bool isOnline)

[signal] void QNetworkConfigurationManager::updateCompleted()

[slot] void QNetworkConfigurationManager::updateConfigurations()