Home · Overviews · Examples 

QHostInfo Class Reference
[com.trolltech.qt.network module]

The QHostInfo class provides static functions for host name lookups. More...


Detailed Description

The QHostInfo class provides static functions for host name lookups.

QHostInfo uses the lookup mechanisms provided by the operating system to find the IP address(es) associated with a host name, or the host name associated with an IP address. The class provides two static convenience functions: one that works asynchronously and emits a signal once the host is found, and one that blocks and returns a QHostInfo object.

To look up a host's IP addresses asynchronously, call lookupHost(), which takes the host name or IP address, a receiver object, and a slot signature as arguments and returns an ID. You can abort the lookup by calling abortHostLookup with the lookup ID.

Example:

    // To find the IP address of www.trolltech.com
    QHostInfo::lookupHost("www.trolltech.com",
                          this, SLOT(printResults(QHostInfo)));

    // To find the host name for 4.2.2.1
    QHostInfo::lookupHost("4.2.2.1",
                          this, SLOT(printResults(QHostInfo)));

The slot is invoked when the results are ready. (If you use Qtopia Core and disabled multithread support by defining QT_NO_THREAD, lookupHost() will block until the lookup has finished.) The results are stored in a QHostInfo object. Call addresses to get the list of IP addresses for the host, and hostName to get the host name that was looked up.

If the lookup failed, error returns the type of error that occurred. errorString gives a human-readable description of the lookup error.

If you want a blocking lookup, use the QHostInfo::fromName() function:

    QHostInfo info = QHostInfo::fromName("www.trolltech.com");

QHostInfo supports Internationalized Domain Names (IDNs) through the IDNA and Punycode standards.

To retrieve the name of the local host, use the static QHostInfo::localHostName() function.

See also QAbstractSocket and RFC 3492.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.5_01