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

# QDns Class Reference

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

    #include <QDns>

Note: All the functions in this class are reentrant.

- List of all members, including inherited members

### Static Public Members

- void getHostByName ( const QString & name, QObject * receiver, const char * member )
- QDnsHostInfo getHostByName ( const QString & name )
- QString getHostName ()

## Detailed Description

The QDns class provides static functions for host name lookups.

QDns uses the lookup mechanisms provided by the operating system to find the IP addresses of a host name. It provides two static convenience functions, one that works asynchronously and emits a signal once the host is found, and one that blocks.

To look up a host's IP address asynchronously, call getHostByName(), which takes the host name and a slot signature as arguments. The lookup is asynchronous by default. If Qt is built without thread support, this function blocks until the lookup has finished.

        QDns::getHostByName("www.example.com", this, SLOT(printResults(const QDnsHostInfo &)));

The slot is invoked once the results are ready.

If you want a blocking lookup use the overloaded getHostByName() that takes a single string argument (the hostname).

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

See also QDnsHostInfo and l{http://ietf.org/rfc/rfc3492}{RFC 3492}.

## Member Function Documentation

### void QDns::getHostByName ( const QString & name, QObject * receiver, const char * member ) `[static]`

Looks up the hostname (IP address) name. When the result of the lookup is ready, the slot or signal member in receiver is called with a QDnsHostInfo argument. The QDnsHostInfo object can then be inspected to get the results of the lookup.

Example:

The lookup is performed by a single function call:

        QDns::getHostByName("www.trolltech.com", this, SLOT(lookedUp(const QDnsHostInfo &)));

The implementation of the slot prints basic information about the addresses returned by the lookup, or reports an error if it failed:

        void MyWidget::lookedUp(const QDnsHostInfo &host)
        {
            if (host.error() != QDns::NoError) {
                qDebug("Lookup failed: %s", host.errorString().latin1());
                return;
            }

            QList<QHostAddress> addresses = host.addresses();
            for (int i = 0; i < addresses.count(); ++i)
                qDebug("Got address: %s", addresses.at(i).toString().latin1());
        }

### QDnsHostInfo QDns::getHostByName ( const QString & name ) `[static]`

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

This function looks up the IP address for the given host name. The function blocks during the lookup which means that execution of the program is suspended until the results of the lookup are ready. Returns the result of the lookup.

### QString QDns::getHostName () `[static]`

Returns the host name of this machine.