Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
The QDns class provides static functions for host name lookups. More...
#include <QDns>
Note: All the functions in this class are reentrant.
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}.
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()); }
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.
Returns the host name of this machine.
Copyright © 2004 Trolltech | Trademarks | Qt 4.0.0-b1 |