CopperSpice API
1.9.2
|
The QHostInfo class provides static functions for host name lookups. More...
Public Types | |
enum | HostInfoError |
Public Methods | |
QHostInfo (const QHostInfo &other) | |
QHostInfo (int id=-1) | |
QHostInfo (QHostInfo &&other) | |
~QHostInfo () | |
QList< QHostAddress > | addresses () const |
HostInfoError | error () const |
QString | errorString () const |
QString | hostName () const |
int | lookupId () const |
QHostInfo & | operator= (const QHostInfo &other) |
QHostInfo & | operator= (QHostInfo &&other) |
void | setAddresses (const QList< QHostAddress > &addresses) |
void | setError (HostInfoError error) |
void | setErrorString (const QString &errorStr) |
void | setHostName (const QString &hostName) |
void | setLookupId (int id) |
Static Public Methods | |
static void | abortHostLookup (int id) |
static QHostInfo | fromName (const QString &name) |
static QString | localDomainName () |
static QString | localHostName () |
static int | lookupHost (const QString &name, QObject *receiver, const QString &member) |
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 methods: one which works asynchronously and emits a signal once the host is found, and a second one 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.
The slot is invoked when the results are ready. 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() method.
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() method. QHostInfo uses multiple threads for DNS lookup instead of one dedicated DNS thread.
This enum describes the various errors that can occur when trying to resolve a host name.
Constant | Value | Description |
---|---|---|
QHostInfo::NoError | 0 | The lookup was successful. |
QHostInfo::HostNotFound | 1 | No IP addresses were found for the host. |
QHostInfo::UnknownError | 2 | An unknown error occurred. |
|
explicit |
Constructs an empty QHostInfo with the given lookup id.
QHostInfo::QHostInfo | ( | const QHostInfo & | other | ) |
Copy constructs a new QHostInfo from other.
QHostInfo::QHostInfo | ( | QHostInfo && | other | ) |
Move constructs a new QHostInfo from other.
QHostInfo::~QHostInfo | ( | ) |
Destroys the host info object.
|
static |
Aborts the host lookup with the given id as returned by lookupHost().
QList< QHostAddress > QHostInfo::addresses | ( | ) | const |
Returns the list of IP addresses associated with hostName(). This list may be empty.
HostInfoError QHostInfo::error | ( | ) | const |
Returns the type of error that occurred if the host name lookup failed, otherwise returns NoError.
QString QHostInfo::errorString | ( | ) | const |
If the lookup failed, this method returns a human readable description of the error, otherwise "Unknown error" is returned.
|
static |
Looks up the IP address(es) 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 in a QHostInfo object.
If you pass a literal IP address to name instead of a host name, QHostInfo will search for the domain name for the IP (i.e., QHostInfo will perform a reverse lookup). On success, the returned QHostInfo will contain both the resolved domain name and IP addresses for the host name.
QString QHostInfo::hostName | ( | ) | const |
Returns the name of the host whose IP addresses were looked up.
|
static |
Returns the DNS domain of this machine. DNS domains are not related to domain names found in Windows networks.
|
static |
Returns the host name of this machine.
|
static |
Looks up the IP address(es) associated with host with the given name and returns an ID for the lookup. When the result of the lookup is ready, the slot or signal member in receiver is called with a QHostInfo argument. The QHostInfo object can then be inspected to get the results of the lookup.
The implementation of the slot prints basic information about the addresses returned by the lookup, or reports an error if it failed.
If you pass a literal IP address to name instead of a host name, QHostInfo will search for the domain name for the IP (i.e., QHostInfo will perform a reverse lookup). On success, the resulting QHostInfo will contain both the resolved domain name and IP addresses for the host name.
int QHostInfo::lookupId | ( | ) | const |
Returns the ID of this lookup.
QHostInfo & QHostInfo::operator= | ( | const QHostInfo & | other | ) |
Copy assigns from other and returns a reference to this object.
QHostInfo & QHostInfo::operator= | ( | QHostInfo && | other | ) |
Move assigns from other and returns a reference to this object.
void QHostInfo::setAddresses | ( | const QList< QHostAddress > & | addresses | ) |
Sets the list of addresses in this QHostInfo to addresses.
void QHostInfo::setError | ( | HostInfoError | error | ) |
Sets the error type of this QHostInfo to error.
void QHostInfo::setErrorString | ( | const QString & | errorStr | ) |
Sets the human readable description of the error that occurred to errorStr if the lookup failed.
void QHostInfo::setHostName | ( | const QString & | hostName | ) |
Sets the host name of this QHostInfo to hostname.
void QHostInfo::setLookupId | ( | int | id | ) |
Sets the ID of this lookup to id.