|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.network.QHostInfo
public class QHostInfo
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 www.trolltech.com QHostInfo::lookupHost("www.trolltech.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. (If you use Qtopia Core and disabled multithread support by defining QT_NO_THREAD, lookupHost() will block until the lookup has finished.) 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("www.trolltech.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.
Nested Class Summary | |
---|---|
static class |
QHostInfo.HostInfoError
This enum describes the various errors that can occur when trying to resolve a host name. |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Constructor Summary | |
---|---|
QHostInfo()
Equivalent to QHostInfo(-1). |
|
QHostInfo(int lookupId)
Constructs an empty host info object with lookup ID lookupId. |
|
QHostInfo(QHostInfo d)
Constructs a copy of d. |
Method Summary | |
---|---|
static void |
abortHostLookup(int lookupId)
Aborts the host lookup with the ID lookupId, as returned by lookupHost(). |
java.util.List<QHostAddress> |
addresses()
Returns the list of IP addresses associated with hostName. |
QHostInfo.HostInfoError |
error()
Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError. |
java.lang.String |
errorString()
If the lookup failed, this function returns a human readable description of the error; otherwise "Unknown error" is returned. |
static QHostInfo |
fromName(java.lang.String name)
Looks up the IP address(es) for the given host name. |
static QHostInfo |
fromNativePointer(QNativePointer nativePointer)
This function returns the QHostInfo instance pointed to by nativePointer |
java.lang.String |
hostName()
Returns the name of the host whose IP addresses were looked up. |
static java.lang.String |
localHostName()
Returns the host name of this machine. |
int |
lookupId()
Returns the ID of this lookup. |
static QNativePointer |
nativePointerArray(QHostInfo[] array)
This function returns a QNativePointer that is pointing to the specified QHostInfo array. |
void |
setAddresses(java.util.List<QHostAddress> addresses)
Sets the list of addresses in this QHostInfo to addresses. |
void |
setError(QHostInfo.HostInfoError error)
Sets the error type of this QHostInfo to error. |
void |
setErrorString(java.lang.String errorString)
Sets the human readable description of the error that occurred to errorString if the lookup failed. |
void |
setHostName(java.lang.String name)
Sets the host name of this QHostInfo to name. |
void |
setLookupId(int id)
Sets the ID of this lookup to id. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QHostInfo()
Equivalent to QHostInfo(-1).
public QHostInfo(int lookupId)
Constructs an empty host info object with lookup ID lookupId.
public QHostInfo(QHostInfo d)
Constructs a copy of d.
Method Detail |
---|
public final java.util.List<QHostAddress> addresses()
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
}
public final QHostInfo.HostInfoError error()
Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError.
public final java.lang.String errorString()
If the lookup failed, this function returns a human readable description of the error; otherwise "Unknown error" is returned.
public final java.lang.String hostName()
Returns the name of the host whose IP addresses were looked up.
public final int lookupId()
Returns the ID of this lookup.
public final void setAddresses(java.util.List<QHostAddress> addresses)
Sets the list of addresses in this QHostInfo to addresses.
public final void setError(QHostInfo.HostInfoError error)
Sets the error type of this QHostInfo to error.
public final void setErrorString(java.lang.String errorString)
Sets the human readable description of the error that occurred to errorString if the lookup failed.
public final void setHostName(java.lang.String name)
Sets the host name of this QHostInfo to name.
public final void setLookupId(int id)
Sets the ID of this lookup to id.
public static void abortHostLookup(int lookupId)
Aborts the host lookup with the ID lookupId, as returned by lookupHost().
public static QHostInfo fromName(java.lang.String name)
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.
public static java.lang.String localHostName()
Returns the host name of this machine.
public static QHostInfo fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QHostInfo[] array)
array
- the array that the returned pointer will point to.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |