QHostAddress Class
The QHostAddress class provides an IP address. More...
| Header: | #include <QHostAddress> |
| qmake: | QT += network |
Public Types
| enum | ConversionModeFlag { StrictConversion, ConvertV4MappedToIPv4, ConvertV4CompatToIPv4, ConvertLocalHost, ConvertUnspecifiedAddress, TolerantConversion } |
| enum | SpecialAddress { Null, LocalHost, LocalHostIPv6, Broadcast, AnyIPv4, …, Any } |
Detailed Description
This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.
QHostAddress is normally used with the QTcpSocket, QTcpServer, and QUdpSocket to connect to a host or to set up a server.
A host address is set with setAddress(), and retrieved with toIPv4Address(), toIPv6Address(), or toString(). You can check the type with protocol().
Note: Please note that QHostAddress does not do DNS lookups. QHostInfo is needed for that.
The class also supports common predefined addresses: Null, LocalHost, LocalHostIPv6, Broadcast, and Any.
See also QHostInfo, QTcpSocket, QTcpServer, and QUdpSocket.
Member Type Documentation
enum QHostAddress::ConversionModeFlag
| Constant | Value | Description |
|---|---|---|
QHostAddress::StrictConversion | 0 | Don't convert IPv6 addresses to IPv4 when comparing two QHostAddress objects of different protocols, so they will always be considered different. |
QHostAddress::ConvertV4MappedToIPv4 | 1 | Convert IPv4-mapped IPv6 addresses (RFC 4291 sect. 2.5.5.2) when comparing. Therefore QHostAddress("::ffff:192.168.1.1") will compare equal to QHostAddress("192.168.1.1"). |
QHostAddress::ConvertV4CompatToIPv4 | 2 | Convert IPv4-compatible IPv6 addresses (RFC 4291 sect. 2.5.5.1) when comparing. Therefore QHostAddress("::192.168.1.1") will compare equal to QHostAddress("192.168.1.1"). |
QHostAddress::ConvertLocalHost | 8 | Convert the IPv6 loopback addresses to its IPv4 equivalent when comparing. Therefore e.g. QHostAddress("::1") will compare equal to QHostAddress("127.0.0.1"). |
QHostAddress::ConvertUnspecifiedAddress | 4 | All unspecified addresses will compare equal, namely AnyIPv4, AnyIPv6 and Any. |
QHostAddress::TolerantConversion | 0xff | Sets all three preceding flags. |
This enum was introduced or modified in Qt 5.8.
See also isEqual().
enum QHostAddress::SpecialAddress
| Constant | Value | Description |
|---|---|---|
QHostAddress::Null | 0 | The null address object. Equivalent to QHostAddress(). See also QHostAddress::isNull(). |
QHostAddress::LocalHost | 2 | The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1"). |
QHostAddress::LocalHostIPv6 | 3 | The IPv6 localhost address. Equivalent to QHostAddress("::1"). |
QHostAddress::Broadcast | 1 | The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255"). |
QHostAddress::AnyIPv4 | 6 | The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interfaces. |
QHostAddress::AnyIPv6 | 5 | The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interfaces. |
QHostAddress::Any | 4 | The dual stack any-address. A socket bound with this address will listen on both IPv4 and IPv6 interfaces. |