Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.network
Class QHostInfo

    java.lang.Object
      com.trolltech.qt.internal.QSignalEmitterInternal
          com.trolltech.qt.QSignalEmitter
              com.trolltech.qt.QtJambiObject
                  com.trolltech.qt.network.QHostInfo

All Implemented Interfaces:
  QtJambiInterface, java.lang.Cloneable

    public class QHostInfo

extends QtJambiObject
implements java.lang.Cloneable

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.

See also:
  `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

### QHostInfo

    public QHostInfo(QHostInfo d)

  Constructs a copy of `other`.

### QHostInfo

    public QHostInfo()

  Constructs an empty host info object with lookup ID `id`.

See also:
  `lookupId()`.

### QHostInfo

    public QHostInfo(int lookupId)

  Constructs an empty host info object with lookup ID `id`.

See also:
  `lookupId()`.

Method Detail

### addresses

    public final java.util.List addresses()

  Returns the list of IP addresses associated with `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
              }

See also:
  `setAddresses()`, `hostName()`, and `error()`.

### error

    public final QHostInfo.HostInfoError error()

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

See also:
  `setError()`, and `errorString()`.

### errorString

    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.

See also:
  `setErrorString()`, and `error()`.

### hostName

    public final java.lang.String hostName()

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

See also:
  `setHostName()`, and `localHostName()`.

### lookupId

    public final int lookupId()

  Returns the ID of this lookup.

See also:
  `setLookupId()`, `abortHostLookup()`, and `hostName()`.

### setAddresses

    public final void setAddresses(java.util.List addresses)

  Sets the list of addresses in this `QHostInfo` to `addresses`.

See also:
  `addresses()`.

### setError

    public final void setError(QHostInfo.HostInfoError error)

  Sets the error type of this `QHostInfo` to `error`.

See also:
  `error()`, and `errorString()`.

### setErrorString

    public final void setErrorString(java.lang.String errorString)

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

See also:
  `errorString()`, and `setError()`.

### setHostName

    public final void setHostName(java.lang.String name)

  Sets the host name of this `QHostInfo` to `hostName`.

See also:
  `hostName()`.

### setLookupId

    public final void setLookupId(int id)

  Sets the ID of this lookup to `id`.

See also:
  `lookupId()`, and `lookupHost()`.

### abortHostLookup

    public static void abortHostLookup(int lookupId)

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

See also:
  `lookupHost()`, and `lookupId()`.

### fromName

    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.

See also:
  `lookupHost()`.

### localHostName

    public static java.lang.String localHostName()

  Returns the host name of this machine.

See also:
  `hostName()`.

### lookupHost

    public 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. 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.

  Parameters:
    `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.

### lookupHost

    public 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. 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.

  Parameters:
    `name` - The host name.
    `signal` - The signal to emit. Must take a single `QHostInfo` argument, and must be contained in a `QObject` subclass.

### clone

    public QHostInfo clone()

  Overrides:
    `clone` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD