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

QHostAddress Class Reference

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

#include <QHostAddress>

List of all members.

Public Functions


Detailed Description

The QHostAddress class provides an IP address.

This class holds an IP address in a platform and protocol independent manner. It stores both IPv4 and IPv6 addresses in a way that you can easily access on any platform.

QHostAddress is normally used with the classes QSocket, QServerSocket, and QSocketDevice to set up a server, or to connect to a host.

A host address is set with setAddress(), checked for its type using isIPv4Address() or isIPv6Address(), and retrieved with toIPv4Address(), toIPv6Address(), or toString().

See also QSocket, QServerSocket, and QSocketDevice.


Member Function Documentation

QHostAddress::QHostAddress ()

Creates a host address object with the IP address 0.0.0.0.

See also clear().

QHostAddress::QHostAddress ( Q_UINT32 ip4Addr )

Creates a host address object for the IPv4 address, ip4Addr.

QHostAddress::QHostAddress ( Q_UINT8 * ip6Addr )

Creates a host address object for the specified IPv6 address.

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

QHostAddress::QHostAddress ( const Q_IPV6ADDR & ip6Addr )

Creates a host address object for the IPv6 address, ip6Addr.

QHostAddress::QHostAddress ( const QHostAddress & address )

Creates a copy of the given address.

QHostAddress::~QHostAddress ()   [virtual]

Destroys the host address object.

void QHostAddress::clear ()

Sets the host address to 0.0.0.0.

bool QHostAddress::isIPv4Address () const

Returns true if this host address represents an IPv4 address; otherwise returns false.

bool QHostAddress::isIPv6Address () const

Returns true if this host address represents an IPv6 address; otherwise returns false.

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.

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

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.c[] contains 16 unsigned characters

    for (int i = 0; i < 16; ++i) {
        // process addr.c[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.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp1