|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.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, "printResults(QHostInfo)"); // To find the host name for 4.2.2.1 QHostInfo.lookupHost("4.2.2.1", this, "printResults(QHostInfo)");The slot is invoked when the results are ready. (If you use Qt for Embedded Linux and disabled multithreading 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.
QAbstractSocket
, and
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.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QHostInfo()
Constructs an empty host info object with lookup ID id. |
|
QHostInfo(int lookupId)
Constructs an empty host info object with lookup ID id. |
|
QHostInfo(QHostInfo d)
Constructs a copy of other. |
Method Summary | |
---|---|
static void |
abortHostLookup(int lookupId)
Aborts the host lookup with the ID id, as returned by lookupHost() . |
java.util.List |
addresses()
Returns the list of IP addresses associated with hostName() . |
QHostInfo |
clone()
|
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. |
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. |
static int |
lookupHost(java.lang.String name,
QObject receiver,
java.lang.String methodName)
Looks up the IP address(es) associated with host name name ,
and returns an ID for the lookup. |
static int |
lookupHost(java.lang.String name,
QSignalEmitter.Signal1 signal)
Looks up the IP address(es) associated with host name name ,
and returns an ID for the lookup. |
int |
lookupId()
Returns the ID of this lookup. |
void |
setAddresses(java.util.List 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 str if the lookup failed. |
void |
setHostName(java.lang.String name)
Sets the host name of this QHostInfo to hostName. |
void |
setLookupId(int id)
Sets the ID of this lookup to id. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
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(QHostInfo d)
public QHostInfo()
lookupId()
.
public QHostInfo(int lookupId)
lookupId()
.
Method Detail |
---|
public final java.util.List addresses()
hostName()
. This list may be empty. Example:
QHostInfo info = new QHostInfo(); // ... if (!info.addresses().isEmpty()) { QHostAddress address = info.addresses().get(0); // use the first IP address }
setAddresses()
, hostName()
, and error()
.
public final QHostInfo.HostInfoError error()
NoError
. setError()
, and errorString()
.
public final java.lang.String errorString()
setErrorString()
, and error()
.
public final java.lang.String hostName()
setHostName()
, and localHostName()
.
public final int lookupId()
setLookupId()
, abortHostLookup()
, and hostName()
.
public final void setAddresses(java.util.List addresses)
addresses()
.
public final void setError(QHostInfo.HostInfoError error)
error()
, and errorString()
.
public final void setErrorString(java.lang.String errorString)
errorString()
, and setError()
.
public final void setHostName(java.lang.String name)
hostName()
.
public final void setLookupId(int id)
lookupId()
, and lookupHost()
.
public static void abortHostLookup(int lookupId)
lookupHost()
. lookupHost()
, and lookupId()
.
public static QHostInfo fromName(java.lang.String name)
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.
lookupHost()
.
public static java.lang.String localHostName()
hostName()
.
public static int lookupHost(java.lang.String name, QObject receiver, java.lang.String methodName)
name
,
and returns an ID for the lookup. When the result of the lookup is ready,
the specified method in receiver
is called with a
QHostInfo
argument. The QHostInfo
object can
then be inspected to get the results of the lookup.
name
- The host name.receiver
- The object on which the method will be called.methodName
- The name of a method which takes a single QHostInfo
argument.public static int lookupHost(java.lang.String name, QSignalEmitter.Signal1 signal)
name
,
and returns an ID for the lookup. When the result of the lookup is ready,
the specified signal is emitted with a QHostInfo
argument.
The QHostInfo
object can then be inspected to get the results
of the lookup.
name
- The host name.signal
- The signal to emit. Must take a single QHostInfo
argument, and must be contained in a QObject
subclass.public QHostInfo clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |