Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QHostAddress Class Reference

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

#include <QHostAddress>

Public Types

Public Functions


Detailed Description

The QHostAddress class provides an IP address.

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(), checked for its type using isIPv4Address() or isIPv6Address(), and retrieved with toIPv4Address(), toIPv6Address(), or toString().

The class also supports common predefined addresses: Null, LocalHost, LocalHostIPv6, Broadcast, and Any.

See also QTcpSocket, QTcpServer, and QUdpSocket.


Member Type Documentation

enum QHostAddress::SpecialAddress

QHostAddress::NullThe null address object. Equivalent to QHostAddress().
QHostAddress::LocalHostThe IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1").
QHostAddress::LocalHostIPv6The IPv6 localhost address. Equivalent to QHostAddress("::1").
QHostAddress::BroadcastThe IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255").
QHostAddress::AnyThe IPv4 any-address. Equivalent to QHostAddress("0.0.0.0").
QHostAddress::AnyIPv6The IPv6 any-address. Equivalent to QHostAddress("::").

Member Function Documentation

QHostAddress::QHostAddress ()

Constructs a host address object with the IP address 0.0.0.0.

See also clear().

QHostAddress::QHostAddress ( Q_UINT32 ip4Addr )

Constructs a host address object with the IPv4 address ip4Addr.

QHostAddress::QHostAddress ( Q_UINT8 * ip6Addr )

Constructs a host address object with the IPv6 address ip6Addr.

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

QHostAddress::QHostAddress ( const Q_IPV6ADDR & ip6Addr )

Constructs a host address object with the IPv6 address ip6Addr.

QHostAddress::QHostAddress ( const QString & address )

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

See also setAddress().

QHostAddress::QHostAddress ( const QHostAddress & address )

Constructs a copy of the given address.

QHostAddress::QHostAddress ( SpecialAddress address )

Constructs a QHostAddress object for address.

QHostAddress::~QHostAddress ()

Destroys the host address object.

void QHostAddress::clear ()

Sets the host address to 0.0.0.0.

bool QHostAddress::isNull () const

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.

Qt::NetworkLayerProtocol QHostAddress::protocol () const

Returns the network layer protocol of the host address.

void QHostAddress::setAddress ( Q_UINT32 ip4Addr )

Set the IPv4 address specified by ip4Addr.

void QHostAddress::setAddress ( Q_UINT8 * ip6Addr )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Set the IPv6 address specified by ip6Addr.

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

void QHostAddress::setAddress ( const Q_IPV6ADDR & ip6Addr )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Set the IPv6 address specified by ip6Addr.

### Add more docs later

bool QHostAddress::setAddress ( const QString & address )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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.

Q_UINT32 QHostAddress::toIPv4Address () 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 only valid if isIp4Addr() returns true.

See also toString().

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.ip6Addr();
    // addr contains 16 unsigned characters

    for (int i = 0; i < 16; ++i) {
        // process addr[i]
    }

This value is only valid if isIPv6Address() returns true.

See also 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".

See also toIPv4Address().

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

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

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

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

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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


Copyright © 2004 Trolltech Trademarks
Qt 4.0.0-b1