Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtNetwork.QHostInfo Class Reference

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

Inheritance diagram for QtNetwork.QHostInfo:
Collaboration diagram for QtNetwork.QHostInfo:

Public Types

enum  HostInfoError { HostNotFound = 1, NoError = 0, UnknownError = 2 }
  More...
 

Public Member Functions

 QHostInfo (QHostInfo d)
 
 
 QHostInfo (int lookupId=-1)
 
 
virtual void CreateProxy ()
 
new void Dispose ()
 

Static Public Member Functions

static void AbortHostLookup (int lookupId)
 
 
static QHostInfo FromName (string name)
 
 
static string LocalDomainName ()
 
 
static string LocalHostName ()
 
 
static int LookupHost (string name, QObject receiver, string member)
 
 

Protected Member Functions

 QHostInfo (System.Type dummy)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

new
System.Collections.Generic.List
< QHostAddress
Addresses [get, set]
 
 
new QHostInfo.HostInfoError Error [get, set]
 
 
new string ErrorString [get, set]
 
 
new string HostName [get, set]
 
 
new int LookupId [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 

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 qt.nokia.com

QHostInfo::lookupHost("qt.nokia.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. 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("qt.nokia.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.

Note: Since Qt 4.6.1 QHostInfo is using multiple threads for DNS lookup instead of one dedicated DNS thread. This improves performance, but also changes the order of signal emissions when using lookupHost() compared to previous versions of Qt. Note: Since Qt 4.6.3 QHostInfo is using a small internal 60 second DNS cache for performance improvements.

See also QAbstractSocket and RFC 3492.

Member Enumeration Documentation

This enum describes the various errors that can occur when trying to resolve a host name.

See also error() and setError().

Enumerator:
HostNotFound 

No IP addresses were found for the host.

NoError 

The lookup was successful.

UnknownError 

An unknown error occurred.

Constructor & Destructor Documentation

QtNetwork.QHostInfo.QHostInfo ( System.Type  dummy)
protected
QtNetwork.QHostInfo.QHostInfo ( QHostInfo  d)

Constructs a copy of other.

QtNetwork.QHostInfo.QHostInfo ( int  lookupId = -1)

Constructs an empty host info object with lookup ID id.

See also lookupId().

Member Function Documentation

static void QtNetwork.QHostInfo.AbortHostLookup ( int  lookupId)
static

Aborts the host lookup with the ID id, as returned by lookupHost().

See also lookupHost() and lookupId().

virtual void QtNetwork.QHostInfo.CreateProxy ( )
virtual
new void QtNetwork.QHostInfo.Dispose ( )
static QHostInfo QtNetwork.QHostInfo.FromName ( string  name)
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.

See also lookupHost().

static string QtNetwork.QHostInfo.LocalDomainName ( )
static

Returns the DNS domain of this machine.

Note: DNS domains are not related to domain names found in Windows networks.

See also hostName().

static string QtNetwork.QHostInfo.LocalHostName ( )
static

Returns the host name of this machine.

See also hostName().

static int QtNetwork.QHostInfo.LookupHost ( string  name,
QObject  receiver,
string  member 
)
static

Looks up the IP address(es) associated with host name 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 lookup is performed by a single function call, for example:

QHostInfo::lookupHost("www.kde.org",

this, SLOT(lookedUp(QHostInfo)));

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 QHostInfo &host)

{

if (host.error() != QHostInfo::NoError) {

qDebug() << "Lookup failed:" << host.errorString();

return;

}

foreach (const QHostAddress &address, host.addresses())

qDebug() << "Found address:" << address.toString();

}

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. Example:

QHostInfo::lookupHost("4.2.2.1",

this, SLOT(lookedUp(QHostInfo)));

Note: There is no guarantee on the order the signals will be emitted if you start multiple requests with lookupHost().

See also abortHostLookup(), addresses(), error(), and fromName().

Member Data Documentation

SmokeInvocation QtNetwork.QHostInfo.interceptor
protected

Property Documentation

new System.Collections.Generic.List<QHostAddress> QtNetwork.QHostInfo.Addresses
getsetadd

Returns the list of IP addresses associated with hostName(). This list may be empty.

Example:

QHostInfo info;

...

if (!info.addresses().isEmpty()) {

QHostAddress address = info.addresses().first();

// use the first IP address

}

Sets the list of addresses in this QHostInfo to addresses.

new QHostInfo.HostInfoError QtNetwork.QHostInfo.Error
getset

Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError.

Sets the error type of this QHostInfo to error.

new string QtNetwork.QHostInfo.ErrorString
getset

If the lookup failed, this function returns a human readable description of the error; otherwise "Unknown error" is returned.

Sets the human readable description of the error that occurred to str if the lookup failed.

new string QtNetwork.QHostInfo.HostName
getset

Returns the name of the host whose IP addresses were looked up.

Sets the host name of this QHostInfo to hostName.

new int QtNetwork.QHostInfo.LookupId
getset

Returns the ID of this lookup.

Sets the ID of this lookup to id.

virtual System.IntPtr QtNetwork.QHostInfo.SmokeObject
getset