CSDN话题挑战赛第2期
参赛话题:Qt应用程序开发
1.详细描述
QNetworkConfiguration类提供了一个或多个接入点配置的抽象。
QNetworkConfiguration封装了一个单一的接入点或服务网络。在大多数情况下,单个接入点配置可以映射到一个网络接口。然而,一个网络接口可能并不总是只映射到一个接入点配置。同一网络设备的多个配置可以启用多个接入点。一个可能表现出这种配置的设备可能是智能手机,它允许用户管理多个WLAN配置,而设备本身只有一个WLAN网络设备。
QNetworkConfiguration还支持服务网络的概念。这个概念允许将多个接入点配置组合成一个实体。这样的组被称为服务网络,在需要到特定目标网络的网络会话的情况下(如公司网络),它是有益的。当使用服务网络时,用户通常并不关心选择哪种连接方式(如公司WLAN或通过GPRS的VPN),只要他能到达公司的目标服务器。根据当前的位置和时间,构成服务网络的一些接入点甚至可能无法使用。此外,可以启用自动接入点漫游,使设备能够动态地改变网络接口配置,同时保持与目标网络的应用连接。它允许适应不断变化的环境,并可以在成本、速度或其他网络参数方面实现优化。
UserChoice类型的特殊配置提供了一个占位符配置,当一个会话被打开时,该配置被平台解析为一个实际的网络配置。并非所有平台都支持用户选择配置的概念。
2.配置状态
可用的配置列表可以通过 QNetworkConfigurationManager::allConfigurations() 获得。一个配置可以有多种状态。已定义的配置状态表示该配置已存储在设备上。然而,该配置还没有准备好被激活,例如,一个WLAN可能在当前时间还不能使用。
发现状态意味着配置已被定义,并且外部条件是可以立即使用该配置来打开一个新的网络会话。这种外部条件的一个例子是,以太网电缆实际上已经连接到设备上,或者具有指定SSID的WLAN在范围内。
活动状态意味着配置已被发现。处于这种状态的配置目前正被一个应用程序使用。底层网络接口有一个有效的IP配置,可以在设备和目标网络之间传输IP数据包。
未定义状态表示系统对可能的目标网络有了解,但实际上不能使用这种知识来连接到它。这种状态的一个例子是已经发现了一个加密的WLAN,但用户实际上还没有保存配置,包括允许设备连接到它的必要密码。
根据配置的类型,一些状态在本质上是短暂的。如果GSM/UMTS网络可用,一个GPRS/UMTS连接几乎总是被发现。然而,如果GSM/UMTS网络失去了连接,相关的配置也可能从发现状态变为定义状态。类似的用例可能会被WLAN的可用性所触发。QNetworkConfigurationManager::updateConfigurations() 可以用来手动触发状态的更新。请注意,一些平台不需要这样的更新,因为一旦发现状态,它们就会隐含地改变。如果一个配置的状态改变,所有相关的QNetworkConfiguration实例都会自动改变它们的状态。
参见QNetworkSession和QNetworkConfigurationManager。
3.成员类型说明
enum QNetworkConfiguration::BearerType
指定一个配置所使用的承载类型。
Constant | Value | Description |
---|---|---|
QNetworkConfiguration::BearerUnknown | 0 | The type of bearer is unknown or unspecified. The bearerTypeName() function may return additional information. |
QNetworkConfiguration::BearerEthernet | 1 | The configuration is for an Ethernet interfaces. |
QNetworkConfiguration::BearerWLAN | 2 | The configuration is for a Wireless LAN interface. |
QNetworkConfiguration::Bearer2G | 3 | The configuration is for a CSD, GPRS, HSCSD, EDGE or cdmaOne interface. |
QNetworkConfiguration::Bearer3G | 11 | The configuration is for a 3G interface. |
QNetworkConfiguration::Bearer4G | 12 | The configuration is for a 4G interface. |
QNetworkConfiguration::BearerCDMA2000 | 4 | The configuration is for CDMA interface. |
QNetworkConfiguration::BearerWCDMA | 5 | The configuration is for W-CDMA/UMTS interface. |
QNetworkConfiguration::BearerHSPA | 6 | The configuration is for High Speed Packet Access (HSPA) interface. |
QNetworkConfiguration::BearerBluetooth | 7 | The configuration is for a Bluetooth interface. |
QNetworkConfiguration::BearerWiMAX | 8 | The configuration is for a WiMAX interface. |
QNetworkConfiguration::BearerEVDO | 9 | The configuration is for an EVDO (3G) interface. |
QNetworkConfiguration::BearerLTE | 10 | The configuration is for a LTE (4G) interface. |
enum QNetworkConfiguration::Purpose
指定配置的目的。
Constant | Value | Description |
---|---|---|
QNetworkConfiguration::UnknownPurpose | 0 | The configuration doesn't specify any purpose. This is the default value. |
QNetworkConfiguration::PublicPurpose | 1 | The configuration can be used for general purpose internet access. |
QNetworkConfiguration::PrivatePurpose | 2 | The configuration is suitable to access a private network such as an office Intranet. |
QNetworkConfiguration::ServiceSpecificPurpose | 3 | The configuration can be used for operator specific services (e.g. receiving MMS messages or content streaming). |
enum QNetworkConfiguration::StateFlag
flags QNetworkConfiguration::StateFlags
指定配置状态。
Constant | Value | Description |
---|---|---|
QNetworkConfiguration::Undefined | 0x0000001 | This state is used for transient configurations such as newly discovered WLANs for which the user has not actually created a configuration yet. |
QNetworkConfiguration::Defined | 0x0000002 | Defined configurations are known to the system but are not immediately usable (e.g. a configured WLAN is not within range or the Ethernet cable is currently not plugged into the machine). |
QNetworkConfiguration::Discovered | 0x0000006 | A discovered configuration can be immediately used to create a new QNetworkSession. An example of a discovered configuration could be a WLAN which is within in range. If the device moves out of range the discovered flag is dropped. A second example is a GPRS configuration which generally remains discovered for as long as the device has network coverage. A configuration that has this state is also in state QNetworkConfiguration::Defined. If the configuration is a service network this flag is set if at least one of the underlying access points configurations has the Discovered state. |
QNetworkConfiguration::Active | 0x000000e | The configuration is currently used by an open network session (see QNetworkSession::isOpen()). However this does not mean that the current process is the entity that created the open session. It merely indicates that if a new QNetworkSession were to be constructed based on this configuration QNetworkSession::state() would return QNetworkSession::Connected. This state implies the QNetworkConfiguration::Discovered state. |
The StateFlags type is a typedef for QFlags<StateFlag>. It stores an OR combination of StateFlag values.
enum QNetworkConfiguration::Type
这个枚举描述了配置的类型。
Constant | Value | Description |
---|---|---|
QNetworkConfiguration::InternetAccessPoint | 0 | The configuration specifies the details for a single access point. Note that configurations of type InternetAccessPoint may be part of other QNetworkConfigurations of type ServiceNetwork. |
QNetworkConfiguration::ServiceNetwork | 1 | The configuration is based on a group of QNetworkConfigurations of type InternetAccessPoint. All group members can reach the same target network. This type of configuration is a mandatory requirement for roaming enabled network sessions. On some platforms this form of configuration may also be called Service Network Access Point (SNAP). |
QNetworkConfiguration::UserChoice | 2 | The configuration is a placeholder which will be resolved to an actual configuration by the platform when a session is opened. Depending on the platform the selection may generate a popup dialog asking the user for his preferred choice. |
QNetworkConfiguration::Invalid | 3 | The configuration is invalid. |
4.成员函数说明
QNetworkConfiguration::QNetworkConfiguration()
构建一个无效的配置对象。 参见isValid()。
QNetworkConfiguration::QNetworkConfiguration(const QNetworkConfiguration &other)
创建一个包含在other中的QNetworkConfiguration对象的副本。
QNetworkConfiguration::~QNetworkConfiguration()
释放与QNetworkConfiguration对象相关的资源。
BearerType QNetworkConfiguration::bearerType() const
返回该网络配置所使用的承载类型。 如果承载类型未知,可以使用 bearerTypeName() 函数来检索承载的文本类型名称。 一个无效的网络配置总是返回BearerUnknown值。 另请参见 bearerTypeName() 和 bearerTypeFamily()。
BearerType QNetworkConfiguration::bearerTypeFamily() const
返回该网络配置所使用的承载类型家族。下表列出了bearingerType()值如何映射到bearingerTypeFamily()值:
bearer type | bearer type family |
---|---|
BearerUnknown, Bearer2G, BearerEthernet, BearerWLAN, BearerBluetooth | (same type) |
BearerCDMA2000, BearerEVDO, BearerWCDMA, BearerHSPA, Bearer3G | Bearer3G |
BearerWiMAX, BearerLTE, Bearer4G | Bearer4G |
一个无效的网络配置总是返回BearerUnknown值。
也请看 bearerType() 和 bearerTypeName()。
QString QNetworkConfiguration::bearerTypeName() const
返回该网络配置所使用的承载类型的字符串。 这个字符串没有被翻译,因此不能被显示给用户。随后的表格显示了已知类型的BearerType和承载类型名称之间的固定映射。如果BearerType是未知的,这个函数可能会返回额外的信息,如果它是可用的,否则将返回一个空字符串。
BearerType | Value |
---|---|
BearerUnknown | The session is based on an unknown or unspecified bearer type. The value of the string returned describes the bearer type. |
BearerEthernet | Ethernet |
BearerWLAN | WLAN |
Bearer2G | 2G |
Bearer3G | 3G |
Bearer4G | 4G |
BearerCDMA2000 | CDMA2000 |
BearerWCDMA | WCDMA |
BearerHSPA | HSPA |
BearerBluetooth | Bluetooth |
BearerWiMAX | WiMAX |
BearerEVDO | EVDO |
BearerLTE | LTE |
如果这是一个无效的配置,该函数返回一个空字符串,这是一个QNetworkConfiguration::ServiceNetwork或QNetworkConfiguration::UserChoice类型的网络配置。 也请看 bearerType() 和 bearerTypeFamily()。
QList<QNetworkConfiguration> QNetworkConfiguration::children() const
按优先顺序返回该网络配置的所有子配置。列表中的第一个子配置具有最高的优先级。 只有ServiceNetwork类型的网络配置可以有子配置。否则,此函数返回一个空列表。
int QNetworkConfiguration::connectTimeout() const
返回该配置的连接超时。参见setConnectTimeout。
QString QNetworkConfiguration::identifier() const
返回该网络配置的唯一和平台特定的标识符;否则是一个空字符串。
bool QNetworkConfiguration::isRoamingAvailable() const
如果该配置支持漫游,则返回true;否则返回false。
bool QNetworkConfiguration::isValid() const
如果这个QNetworkConfiguration对象是有效的,则返回true。如果用户删除了配置,或者配置是默认构建的,那么该配置可能会变得无效。 配置的添加和删除可以通过QNetworkConfigurationManager来监控。 请参阅QNetworkConfigurationManager。
QString QNetworkConfiguration::name() const
返回此配置的用户可见名称。 该名称可以是底层接入点的名称或该配置所代表的服务网络的名称。
Purpose QNetworkConfiguration::purpose() const
返回此配置的目的。 目的字段可用于以编程方式确定一个配置的目的。这些信息通常是接入点或服务网络元数据的一部分。
bool QNetworkConfiguration::setConnectTimeout(int timeout)
将此配置的连接超时设置为超时。这允许控制QAbstractSocket用于建立连接的超时。 警告。如果承载插件没有CanStartAndStopInterfaces功能,这将没有效果。 如果成功,返回true。 参见connectTimeout。
StateFlags QNetworkConfiguration::state() const
返回配置的当前状态。
void QNetworkConfiguration::swap(QNetworkConfiguration &other)
将此网络配置与其他网络配置进行交换。这个函数非常快,而且从不失效。
Type QNetworkConfiguration::type() const
返回配置的类型。 一个配置可以代表一个单一的接入点配置或一组接入点配置。这样的一组配置被称为服务网络。一个基于服务网络的配置可以潜在地支持网络会话的漫游。
bool QNetworkConfiguration::operator!=(const QNetworkConfiguration &other) const
如果此配置与给定的其他配置不一样,则返回真,否则返回假。
QNetworkConfiguration &QNetworkConfiguration::operator=(QNetworkConfiguration &&other)
移动分配运算符。
QNetworkConfiguration &QNetworkConfiguration::operator=(const QNetworkConfiguration &other)
将包含在其他对象中的QNetworkConfiguration对象的内容复制到这个对象中。
bool QNetworkConfiguration::operator==(const QNetworkConfiguration &other) const
如果此配置与所给的其他配置相同,则返回真,否则返回假。