Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
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.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.network.QHostInfo

All Implemented Interfaces:
  QtJambiInterface

    public class QHostInfo

extends QtJambiObject

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.

See Also:
  `QAbstractSocket`, RFC 3492

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

### QHostInfo

    public QHostInfo()

  Equivalent to `QHostInfo`(-1).

### QHostInfo

    public QHostInfo(int lookupId)

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

  See Also:
    `lookupId`

### QHostInfo

    public QHostInfo(QHostInfo d)

  Constructs a copy of `d`.

Method Detail

### addresses

    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
          }

  See Also:
    `setAddresses`, `hostName`, `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`, `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`, `error`

### hostName

    public final java.lang.String hostName()

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

  See Also:
    `setHostName`, `localHostName`

### lookupId

    public final int lookupId()

  Returns the ID of this lookup.

  See Also:
    `setLookupId`, `abortHostLookup`, `hostName`

### setAddresses

    public final void setAddresses(java.util.List<QHostAddress> 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`, `errorString`

### setErrorString

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

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

  See Also:
    `errorString`, `setError`

### setHostName

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

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

  See Also:
    `hostName`

### setLookupId

    public final void setLookupId(int id)

  Sets the ID of this lookup to `id`.

  See Also:
    `lookupId`, `lookupHost`

### abortHostLookup

    public static void abortHostLookup(int lookupId)

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

  See Also:
    `lookupHost`, `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`

### fromNativePointer

    public static QHostInfo fromNativePointer(QNativePointer nativePointer)

  This function returns the QHostInfo instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

### nativePointerArray

    public static QNativePointer nativePointerArray(QHostInfo[] array)

  This function returns a QNativePointer that is pointing to the specified QHostInfo array.

  Parameters:
    `array` - the array that the returned pointer will point to.
  Returns:
    a QNativePointer that is pointing to the specified array.

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