QHostAddress Class Reference

[ QtNetwork module]

QHostAddress 类提供 IP 地址。 更多...

类型

方法

Static Methods

Special Methods


详细描述

QHostAddress 类提供 IP 地址。

This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.

QHostAddress 通常被使用于 QTcpSocket , QTcpServer ,和 QUdpSocket to connect to a host or to set up a server.

设置主机地址采用 setAddress (),和检索采有 toIPv4Address (), toIPv6Address (),或 toString (). You can check the type with protocol ().

注意: Please note that QHostAddress does not do DNS lookups. QHostInfo is needed for that.

类还支持常见预定义地址: Null , LocalHost , LocalHostIPv6 , Broadcast ,和 Any .


类型文档编制

QHostAddress.SpecialAddress

常量 描述
QHostAddress.Null 0 null 地址对象。相当于 QHostAddress ().
QHostAddress.LocalHost 2 Pv4 本地主机地址。相当于 QHostAddress ("127.0.0.1")。
QHostAddress.LocalHostIPv6 3 IPv6 本地主机地址。相当于 QHostAddress (".1").
QHostAddress.Broadcast 1 IPv4 广播地址。相当于 QHostAddress ("255.255.255.255")。
QHostAddress.Any 4 IPv4 任意地址。相当于 QHostAddress ("0.0.0.0").
QHostAddress.AnyIPv6 5 IPv6 任意地址。相当于 QHostAddress (" . ").

方法文档编制

QHostAddress.__init__ ( self )

Constructs a host address object with the IP address 0.0.0.0.

另请参阅 clear ().

QHostAddress.__init__ ( self , SpecialAddress   address )

构造主机地址对象采用 IPv4 地址 ip4Addr .

QHostAddress.__init__ ( self , int  ip4Addr )

构造主机地址对象采用 IPv6 地址 ip6Addr .

ip6Addr must be a 16-byte array in network byte order (big endian).

QHostAddress.__init__ ( self , QString  address )

构造主机地址对象采用 IPv6 地址 ip6Addr .

QHostAddress.__init__ ( self , 16-tuple-of-int  ip6Addr )

Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr .

另请参阅 setAddress ().

QHostAddress.__init__ ( self , QHostAddress   copy )

构造 IPv4 或 IPv6 地址基于字符串 address (如 127.0.0.1)。

另请参阅 setAddress ().

QHostAddress.clear ( self )

Sets the host address to 0.0.0.0.

bool QHostAddress.isInSubnet ( self , QHostAddress   subnet , int  netmask )

Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask .

An IP is considered to belong to a subnet if it is contained between the lowest and the highest address in that subnet. In the case of IP version 4, the lowest address is the network address, while the highest address is the broadcast address.

subnet argument does not have to be the actual network address (the lowest address in the subnet). It can be any valid IP belonging to that subnet. In particular, if it is equal to the IP address held by this object, this function will always return true (provided the netmask is a valid value).

该函数在 Qt 4.5 引入。

另请参阅 parseSubnet ().

bool QHostAddress.isInSubnet ( self , tuple-of-QHostAddress-int  subnet )

这是重载函数。

Returns true if this IP is in the subnet described by subnet QHostAddress member of subnet contains the network prefix and the int (second) member contains the netmask (prefix length).

该函数在 Qt 4.5 引入。

bool QHostAddress.isNull ( self )

Returns true if this host address is null (INADDR_ANY or in6addr_any). The default constructor creates a null address, and that address is not valid for any host or interface.

tuple-of-QHostAddress-int QHostAddress.parseSubnet (QString  subnet )

Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length.

The IP address and the netmask must be separated by a slash (/).

This function supports arguments in the form:

For IP version 4, this function accepts as well missing trailing components (i.e., less than 4 octets, like "192.168.1"), followed or not by a dot. If the netmask is also missing in that case, it is set to the number of octets actually passed (in the example above, it would be 24, for 3 octets).

该函数在 Qt 4.5 引入。

另请参阅 isInSubnet ().

QAbstractSocket.NetworkLayerProtocol QHostAddress.protocol ( self )

返回主机地址的网络层协议。

QString QHostAddress.scopeId ( self )

Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty QString 被返回。

The IPv6 scope ID specifies the scope of reachability for non-global IPv6 addresses, limiting the area in which the address can be used. All IPv6 addresses are associated with such a reachability scope. The scope ID is used to disambiguate addresses that are not guaranteed to be globally unique.

IPv6 specifies the following four levels of reachability:

When using a link-local or site-local address for IPv6 connections, you must specify the scope ID. The scope ID for a link-local address is usually the same as the interface name (e.g., "eth0", "en1") or number (e.g., "1", "2").

该函数在 Qt 4.1 引入。

另请参阅 setScopeId ().

QHostAddress.setAddress ( self , int  ip4Addr )

设置 IPv4 地址指定通过 ip4Addr .

bool QHostAddress.setAddress ( self , QString  address )

这是重载函数。

设置 IPv6 地址指定通过 ip6Addr .

ip6Addr must be an array of 16 bytes in network byte order (high-order byte first).

QHostAddress.setAddress ( self , 16-tuple-of-int  ip6Addr )

这是重载函数。

设置 IPv6 地址指定通过 ip6Addr .

QHostAddress.setScopeId ( self , QString  id )

Sets the IPv6 scope ID of the address to id 。若 address protocol is not IPv6, this function does nothing.

该函数在 Qt 4.1 引入。

另请参阅 scopeId ().

int QHostAddress.toIPv4Address ( self )

以数字形式返回 IPv4 地址。

For example, if the address is 127.0.0.1, the returned value is 2130706433 (i.e. 0x7f000001).

This value is only valid if the Protocol() is IPv4Protocol .

另请参阅 toString ().

16-tuple-of-int QHostAddress.toIPv6Address ( self )

Returns the IPv6 address as a Q_IPV6ADDR structure. The structure consists of 16 unsigned characters.

 Q_IPV6ADDR addr = hostAddr.toIPv6Address();
 // addr contains 16 unsigned characters
 for (int i = 0; i < 16; ++i) {
     // process addr[i]
 }
			

This value is only valid if the protocol () 是 IPv6Protocol .

另请参阅 toString ().

QString QHostAddress.toString ( self )

以字符串形式返回地址。

For example, if the address is the IPv4 address 127.0.0.1, the returned string is "127.0.0.1". For IPv6 the string format will follow the RFC5952 recommendation.

另请参阅 toIPv4Address ().

bool QHostAddress.__eq__ ( self , QHostAddress   address )

bool QHostAddress.__eq__ ( self , SpecialAddress   address )

int QHostAddress.__hash__ ( self )

bool QHostAddress.__ne__ ( self , QHostAddress   address )

bool QHostAddress.__ne__ ( self , SpecialAddress   address )