Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QHostAddress Class Reference

The QHostAddress class provides an IP address. More...

#include <qhostaddress.h>

+ Collaboration diagram for QHostAddress:

Public Types

enum  SpecialAddress {
  Null , Broadcast , LocalHost , LocalHostIPv6 ,
  Any , AnyIPv6 , AnyIPv4
}
 \value Null The null address object. More...
 
enum  ConversionModeFlag {
  ConvertV4MappedToIPv4 = 1 , ConvertV4CompatToIPv4 = 2 , ConvertUnspecifiedAddress = 4 , ConvertLocalHost = 8 ,
  TolerantConversion = 0xff , StrictConversion = 0
}
 
enum  NetworkLayerProtocol { IPv4Protocol , IPv6Protocol , AnyIPProtocol , UnknownNetworkLayerProtocol = -1 }
 

Public Member Functions

 QHostAddress ()
 Constructs a null host address object, i.e.
 
 QHostAddress (quint32 ip4Addr)
 Constructs a host address object with the IPv4 address ip4Addr.
 
 QHostAddress (const quint8 *ip6Addr)
 
 QHostAddress (const Q_IPV6ADDR &ip6Addr)
 Constructs a host address object with the IPv6 address ip6Addr.
 
 QHostAddress (const sockaddr *address)
 Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr.
 
 QHostAddress (const QString &address)
 Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1").
 
 QHostAddress (const QHostAddress &copy)
 Constructs a copy of the given address.
 
 QHostAddress (QHostAddress &&other) noexcept=default
 
 QHostAddress (SpecialAddress address)
 Constructs a QHostAddress object for address.
 
 ~QHostAddress ()
 Destroys the host address object.
 
QHostAddressoperator= (QHostAddress &&other) noexcept
 
QHostAddressoperator= (const QHostAddress &other)
 Assigns another host address to this object, and returns a reference to this object.
 
QHostAddressoperator= (SpecialAddress address)
 
void swap (QHostAddress &other) noexcept
 
void setAddress (quint32 ip4Addr)
 Set the IPv4 address specified by ip4Addr.
 
void setAddress (const quint8 *ip6Addr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void setAddress (const Q_IPV6ADDR &ip6Addr)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the IPv6 address specified by ip6Addr.
 
void setAddress (const sockaddr *address)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the native structure sockaddr.
 
bool setAddress (const QString &address)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g.
 
void setAddress (SpecialAddress address)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
NetworkLayerProtocol protocol () const
 Returns the network layer protocol of the host address.
 
quint32 toIPv4Address (bool *ok=nullptr) const
 Returns the IPv4 address as a number.
 
Q_IPV6ADDR toIPv6Address () const
 Returns the IPv6 address as a Q_IPV6ADDR structure.
 
QString toString () const
 Returns the address as a string.
 
QString scopeId () const
 
void setScopeId (const QString &id)
 
bool isEqual (const QHostAddress &address, ConversionMode mode=TolerantConversion) const
 
bool operator== (const QHostAddress &address) const
 Returns true if this host address is the same as the other address given; otherwise returns false.
 
bool operator== (SpecialAddress address) const
 Returns true if this host address is the same as the other address given; otherwise returns false.
 
bool operator!= (const QHostAddress &address) const
 
bool operator!= (SpecialAddress address) const
 Returns true if this host address is not the same as the other address given; otherwise returns false.
 
bool isNull () const
 Returns true if this host address is not valid for any host or interface.
 
void clear ()
 Sets the host address to null and sets the protocol to QAbstractSocket::UnknownNetworkLayerProtocol.
 
bool isInSubnet (const QHostAddress &subnet, int netmask) const
 
bool isInSubnet (const std::pair< QHostAddress, int > &subnet) const
 
bool isLoopback () const
 
bool isGlobal () const
 
bool isLinkLocal () const
 
bool isSiteLocal () const
 
bool isUniqueLocalUnicast () const
 
bool isMulticast () const
 
bool isBroadcast () const
 
bool isPrivateUse () const
 

Static Public Member Functions

static std::pair< QHostAddress, int > parseSubnet (const QString &subnet)
 

Protected Attributes

QExplicitlySharedDataPointer< QHostAddressPrivated
 

Friends

class QHostAddressPrivate
 
Q_NETWORK_EXPORT size_t qHash (const QHostAddress &key, size_t seed=0)
 
bool operator== (QHostAddress::SpecialAddress lhs, const QHostAddress &rhs)
 Returns true if special address lhs is the same as host address rhs; otherwise returns false.
 
bool operator!= (QHostAddress::SpecialAddress lhs, const QHostAddress &rhs)
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &out, const QHostAddress &address)
 Writes host address address to the stream out and returns a reference to the stream.
 
QDataStreamoperator>> (QDataStream &in, QHostAddress &address)
 Reads a host address into address from the stream in and returns a reference to the stream.
 

Detailed Description

The QHostAddress class provides an IP address.

\inmodule QtNetwork

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: \l Null, \l LocalHost, \l LocalHostIPv6, \l Broadcast, and \l Any.

See also
QHostInfo, QTcpSocket, QTcpServer, QUdpSocket

Definition at line 39 of file qhostaddress.h.

Member Enumeration Documentation

◆ ConversionModeFlag

Since
5.8

\value StrictConversion Don't convert IPv6 addresses to IPv4 when comparing two QHostAddress objects of different protocols, so they will always be considered different. \value ConvertV4MappedToIPv4 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"). \value ConvertV4CompatToIPv4 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"). \value ConvertLocalHost 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"). \value ConvertUnspecifiedAddress All unspecified addresses will compare equal, namely AnyIPv4, AnyIPv6 and Any. \value TolerantConversion Sets all three preceding flags.

See also
isEqual()
Enumerator
ConvertV4MappedToIPv4 
ConvertV4CompatToIPv4 
ConvertUnspecifiedAddress 
ConvertLocalHost 
TolerantConversion 
StrictConversion 

Definition at line 52 of file qhostaddress.h.

◆ NetworkLayerProtocol

Enumerator
IPv4Protocol 
IPv6Protocol 
AnyIPProtocol 
UnknownNetworkLayerProtocol 

Definition at line 70 of file qhostaddress.h.

◆ SpecialAddress

\value Null The null address object.

Equivalent to QHostAddress(). See also QHostAddress::isNull(). \value LocalHost The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1"). \value LocalHostIPv6 The IPv6 localhost address. Equivalent to QHostAddress("::1"). \value Broadcast The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255"). \value AnyIPv4 The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interfaces. \value AnyIPv6 The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interfaces. \value Any The dual stack any-address. A socket bound with this address will listen on both IPv4 and IPv6 interfaces.

Enumerator
Null 
Broadcast 
LocalHost 
LocalHostIPv6 
Any 
AnyIPv6 
AnyIPv4 

Definition at line 43 of file qhostaddress.h.

Constructor & Destructor Documentation

◆ QHostAddress() [1/9]

QHostAddress::QHostAddress ( )

Constructs a null host address object, i.e.

an address which is not valid for any host or interface.

See also
clear()

Definition at line 381 of file qhostaddress.cpp.

◆ QHostAddress() [2/9]

QHostAddress::QHostAddress ( quint32 ip4Addr)
explicit

Constructs a host address object with the IPv4 address ip4Addr.

Definition at line 389 of file qhostaddress.cpp.

◆ QHostAddress() [3/9]

QHostAddress::QHostAddress ( const quint8 * ip6Addr)
explicit
Since
5.5 Constructs a host address object with the IPv6 address ip6Addr.

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

Definition at line 402 of file qhostaddress.cpp.

◆ QHostAddress() [4/9]

QHostAddress::QHostAddress ( const Q_IPV6ADDR & ip6Addr)
explicit

Constructs a host address object with the IPv6 address ip6Addr.

Definition at line 411 of file qhostaddress.cpp.

◆ QHostAddress() [5/9]

QHostAddress::QHostAddress ( const sockaddr * sockaddr)
explicit

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

See also
setAddress()

◆ QHostAddress() [6/9]

QHostAddress::QHostAddress ( const QString & address)
explicit

Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1").

See also
setAddress()

Definition at line 423 of file qhostaddress.cpp.

◆ QHostAddress() [7/9]

QHostAddress::QHostAddress ( const QHostAddress & copy)

Constructs a copy of the given address.

Definition at line 449 of file qhostaddress.cpp.

◆ QHostAddress() [8/9]

QHostAddress::QHostAddress ( QHostAddress && other)
defaultnoexcept
Since
6.8

Move-constructs a new QHostAddress from other.

Note
The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

◆ QHostAddress() [9/9]

QHostAddress::QHostAddress ( SpecialAddress address)

Constructs a QHostAddress object for address.

Definition at line 469 of file qhostaddress.cpp.

◆ ~QHostAddress()

QHostAddress::~QHostAddress ( )

Destroys the host address object.

Definition at line 478 of file qhostaddress.cpp.

Member Function Documentation

◆ clear()

void QHostAddress::clear ( )

Sets the host address to null and sets the protocol to QAbstractSocket::UnknownNetworkLayerProtocol.

See also
QHostAddress::Null

Definition at line 532 of file qhostaddress.cpp.

◆ isBroadcast()

bool QHostAddress::isBroadcast ( ) const
Since
5.11

Returns true if the address is the IPv4 broadcast address, false otherwise. The IPv4 broadcast address is 255.255.255.255.

Note that this function does not return true for an IPv4 network's local broadcast address. For that, please use \l QNetworkInterface to obtain the broadcast addresses of the local machine.

See also
isLoopback(), isGlobal(), isMulticast(), isLinkLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1226 of file qhostaddress.cpp.

◆ isEqual()

bool QHostAddress::isEqual ( const QHostAddress & other,
ConversionMode mode = TolerantConversion ) const
Since
5.8

Returns true if this host address is the same as the other address given; otherwise returns false.

The parameter mode controls which conversions are performed between addresses of differing protocols. If no mode is given, TolerantConversion is performed by default.

See also
ConversionMode, operator==()

Definition at line 809 of file qhostaddress.cpp.

◆ isGlobal()

bool QHostAddress::isGlobal ( ) const
Since
5.11

Returns true if the address is an IPv4 or IPv6 global address, false otherwise. A global address is an address that is not reserved for special purposes (like loopback or multicast) or future purposes.

Note that IPv6 unique local unicast addresses are considered global addresses (see isUniqueLocalUnicast()), as are IPv4 addresses reserved for local networks by \l {RFC 1918}.

Also note that IPv6 site-local addresses are deprecated and should be considered as global in new applications. This function returns true for site-local addresses too.

See also
isLoopback(), isSiteLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1134 of file qhostaddress.cpp.

◆ isInSubnet() [1/2]

bool QHostAddress::isInSubnet ( const QHostAddress & subnet,
int netmask ) const
Since
4.5

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.

The 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).

See also
parseSubnet()

Definition at line 927 of file qhostaddress.cpp.

◆ isInSubnet() [2/2]

bool QHostAddress::isInSubnet ( const std::pair< QHostAddress, int > & subnet) const
Since
4.5 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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

Definition at line 975 of file qhostaddress.cpp.

◆ isLinkLocal()

bool QHostAddress::isLinkLocal ( ) const
Since
5.11

Returns true if the address is an IPv4 or IPv6 link-local address, false otherwise.

An IPv4 link-local address is an address in the network 169.254.0.0/16. An IPv6 link-local address is one in the network fe80::/10. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml}{IANA IPv6 Address Space} registry for more information.

See also
isLoopback(), isGlobal(), isMulticast(), isSiteLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1152 of file qhostaddress.cpp.

◆ isLoopback()

bool QHostAddress::isLoopback ( ) const
Since
5.0

returns true if the address is the IPv6 loopback address, or any of the IPv4 loopback addresses.

Definition at line 1112 of file qhostaddress.cpp.

◆ isMulticast()

bool QHostAddress::isMulticast ( ) const
Since
5.6

Returns true if the address is an IPv4 or IPv6 multicast address, false otherwise.

See also
isLoopback(), isGlobal(), isLinkLocal(), isSiteLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1209 of file qhostaddress.cpp.

◆ isNull()

bool QHostAddress::isNull ( ) const

Returns true if this host address is not valid for any host or interface.

The default constructor creates a null address.

See also
QHostAddress::Null

Definition at line 903 of file qhostaddress.cpp.

◆ isPrivateUse()

bool QHostAddress::isPrivateUse ( ) const
Since
6.6

Returns true if the address is an IPv6 unique local unicast address or IPv4 address reserved for local networks by \l {RFC 1918}, false otherwise.

See also
isLoopback(), isGlobal(), isMulticast(), isLinkLocal(), isUniqueLocalUnicast(), isBroadcast()

Definition at line 1239 of file qhostaddress.cpp.

◆ isSiteLocal()

bool QHostAddress::isSiteLocal ( ) const
Since
5.11

Returns true if the address is an IPv6 site-local address, false otherwise.

An IPv6 site-local address is one in the network fec0::/10. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml}{IANA IPv6 Address Space} registry for more information.

IPv6 site-local addresses are deprecated and should not be depended upon in new applications. New applications should not depend on this function and should consider site-local addresses the same as global (which is why isGlobal() also returns true). Site-local addresses were replaced by Unique Local Addresses (ULA).

See also
isLoopback(), isGlobal(), isMulticast(), isLinkLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1175 of file qhostaddress.cpp.

◆ isUniqueLocalUnicast()

bool QHostAddress::isUniqueLocalUnicast ( ) const
Since
5.11

Returns true if the address is an IPv6 unique local unicast address, false otherwise.

An IPv6 unique local unicast address is one in the network fc00::/7. See the \l{https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml} {IANA IPv6 Address Space} registry for more information.

Note that Unique local unicast addresses count as global addresses too. RFC 4193 says that, in practice, "applications may treat these addresses like global scoped addresses." Only routers need care about the distinction.

See also
isLoopback(), isGlobal(), isMulticast(), isLinkLocal(), isUniqueLocalUnicast(), isPrivateUse()

Definition at line 1196 of file qhostaddress.cpp.

◆ operator!=() [1/2]

bool QHostAddress::operator!= ( const QHostAddress & other) const
inline
Since
4.2

Returns true if this host address is not the same as the other address given; otherwise returns false.

Definition at line 116 of file qhostaddress.h.

◆ operator!=() [2/2]

bool QHostAddress::operator!= ( SpecialAddress address) const
inline

Returns true if this host address is not the same as the other address given; otherwise returns false.

Definition at line 118 of file qhostaddress.h.

◆ operator=() [1/3]

QHostAddress & QHostAddress::operator= ( const QHostAddress & other)

Assigns another host address to this object, and returns a reference to this object.

Definition at line 486 of file qhostaddress.cpp.

◆ operator=() [2/3]

QHostAddress & QHostAddress::operator= ( QHostAddress && other)
inlinenoexcept

Definition at line 90 of file qhostaddress.h.

◆ operator=() [3/3]

QHostAddress & QHostAddress::operator= ( SpecialAddress address)
Since
5.8 Assigns the special address address to this object, and returns a reference to this object.
See also
setAddress()

Definition at line 499 of file qhostaddress.cpp.

◆ operator==() [1/2]

bool QHostAddress::operator== ( const QHostAddress & other) const

Returns true if this host address is the same as the other address given; otherwise returns false.

This operator just calls isEqual(other, StrictConversion).

See also
isEqual()

Definition at line 792 of file qhostaddress.cpp.

◆ operator==() [2/2]

bool QHostAddress::operator== ( SpecialAddress address) const

Returns true if this host address is the same as the other address given; otherwise returns false.

Definition at line 862 of file qhostaddress.cpp.

◆ parseSubnet()

std::pair< QHostAddress, int > QHostAddress::parseSubnet ( const QString & subnet)
static
Since
4.5

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: \list

  • 123.123.123.123/n where n is any value between 0 and 32
  • 123.123.123.123/255.255.255.255
  • <ipv6-address>/n where n is any value between 0 and 128 \endlist

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).

See also
isInSubnet()

Definition at line 1005 of file qhostaddress.cpp.

◆ protocol()

QHostAddress::NetworkLayerProtocol QHostAddress::protocol ( ) const

Returns the network layer protocol of the host address.

Definition at line 677 of file qhostaddress.cpp.

◆ scopeId()

QString QHostAddress::scopeId ( ) const
Since
4.1

Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty QString is returned.

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:

\list

  • Node-local: Addresses that are only used for communicating with services on the same interface (e.g., the loopback interface "::1").
  • Link-local: Addresses that are local to the network interface ({link}). There is always one link-local address for each IPv6 interface on your host. Link-local addresses ("fe80...") are generated from the MAC address of the local network adaptor, and are not guaranteed to be unique.
  • Global: For globally routable addresses, such as public servers on the Internet.

\endlist

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").

See also
setScopeId(), QNetworkInterface, QNetworkInterface::interfaceFromName

Definition at line 762 of file qhostaddress.cpp.

◆ setAddress() [1/6]

void QHostAddress::setAddress ( const Q_IPV6ADDR & ip6Addr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Set the IPv6 address specified by ip6Addr.

Definition at line 567 of file qhostaddress.cpp.

◆ setAddress() [2/6]

bool QHostAddress::setAddress ( const QString & address)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g.

"127.0.0.1"). Returns true and sets the address if the address was successfully parsed; otherwise returns false.

Definition at line 581 of file qhostaddress.cpp.

◆ setAddress() [3/6]

void QHostAddress::setAddress ( const quint8 * ip6Addr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.5

Set the IPv6 address specified by ip6Addr.

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

Definition at line 556 of file qhostaddress.cpp.

◆ setAddress() [4/6]

void QHostAddress::setAddress ( const sockaddr * sockaddr)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the IPv4 or IPv6 address specified by the native structure sockaddr.

Returns true and sets the address if the address was successfully parsed; otherwise returns false.

◆ setAddress() [5/6]

void QHostAddress::setAddress ( quint32 ip4Addr)

Set the IPv4 address specified by ip4Addr.

Definition at line 541 of file qhostaddress.cpp.

◆ setAddress() [6/6]

void QHostAddress::setAddress ( SpecialAddress address)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.8

Sets the special address specified by address.

Definition at line 611 of file qhostaddress.cpp.

◆ setScopeId()

void QHostAddress::setScopeId ( const QString & id)
Since
4.1

Sets the IPv6 scope ID of the address to id. If the address protocol is not IPv6, this function does nothing. The scope ID may be set as an interface name (such as "eth0" or "en1") or as an integer representing the interface index. If id is an interface name, QtNetwork will convert to an interface index using QNetworkInterface::interfaceIndexFromName() before calling the operating system networking functions.

See also
scopeId(), QNetworkInterface, QNetworkInterface::interfaceFromName

Definition at line 779 of file qhostaddress.cpp.

◆ swap()

void QHostAddress::swap ( QHostAddress & other)
inlinenoexcept
Since
5.6 \memberswap{host address}

Definition at line 95 of file qhostaddress.h.

◆ toIPv4Address()

quint32 QHostAddress::toIPv4Address ( bool * ok = nullptr) const

Returns the IPv4 address as a number.

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

This value is valid if the protocol() is \l{QAbstractSocket::}{IPv4Protocol}, or if the protocol is \l{QAbstractSocket::}{IPv6Protocol}, and the IPv6 address is an IPv4 mapped address (RFC4291). In those cases, ok will be set to true. Otherwise, it will be set to false.

See also
toString()

Definition at line 663 of file qhostaddress.cpp.

◆ toIPv6Address()

Q_IPV6ADDR QHostAddress::toIPv6Address ( ) const

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]
}
QIPv6Address Q_IPV6ADDR
GLenum const void * addr
[0]

This value is valid if the protocol() is \l{QAbstractSocket::}{IPv6Protocol}. If the protocol is \l{QAbstractSocket::}{IPv4Protocol}, then the address is returned as an IPv4 mapped IPv6 address. (RFC4291)

See also
toString()

Definition at line 696 of file qhostaddress.cpp.

◆ toString()

QString QHostAddress::toString ( ) const

Returns the address as a string.

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. For QHostAddress::Any, its IPv4 address will be returned ("0.0.0.0")

See also
toIPv4Address()

Definition at line 711 of file qhostaddress.cpp.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( QHostAddress::SpecialAddress lhs,
const QHostAddress & rhs )
friend
Since
5.9

Returns false if special address lhs is the same as host address rhs; otherwise returns true.

See also
isEqual()

Definition at line 141 of file qhostaddress.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream & out,
const QHostAddress & address )
related

Writes host address address to the stream out and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1296 of file qhostaddress.cpp.

◆ operator==

bool operator== ( QHostAddress::SpecialAddress lhs,
const QHostAddress & rhs )
friend

Returns true if special address lhs is the same as host address rhs; otherwise returns false.

See also
isEqual()

Definition at line 139 of file qhostaddress.h.

◆ operator>>()

QDataStream & operator>> ( QDataStream & in,
QHostAddress & address )
related

Reads a host address into address from the stream in and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 1327 of file qhostaddress.cpp.

◆ qHash

size_t qHash ( const QHostAddress & key,
size_t seed = 0 )
friend
Since
5.0

Returns a hash of the host address key, using seed to seed the calculation.

Definition at line 1263 of file qhostaddress.cpp.

◆ QHostAddressPrivate

friend class QHostAddressPrivate
friend

Definition at line 145 of file qhostaddress.h.

Member Data Documentation

◆ d

Definition at line 146 of file qhostaddress.h.


The documentation for this class was generated from the following files: