Computer networks such as the internet rely on Domain Name Service (DNS) lookups. This is usually done on remote central servers, but can also be used locally.
There are two classes for doing network lookups—QDnsLookup
and QHostInfo
. QHostInfo
will provide simple IP address lookups for a hostname. It is really just looking up an IP address using a hostname. Let's look at how we can use this.
QHostInfo
is a simple class to do address lookups provided by the platform system. It has synchronous, blocking method for lookup, or you can use signal/slots, as follows:
QHostInfo hInfo = QHostInfo::fromName("www.packtpub.com");
This method blocks until a response is received.
The lookupHost
function does asynchronous lookups and takes a slot as an argument, as follows:
QHostInfo::lookupHost("www.packtpub.com", this, SLOT(lookupResult(QHostInfo)));
The slot we need to implement receives QHostInfo
as an argument, as such:
void SomeClass::lookupResult(QHostInfo info) { if...