Qt Jambi Home

com.trolltech.qt.network
Class QHostAddress

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.network.QHostAddress
All Implemented Interfaces:
QtJambiInterface

public class QHostAddress
extends QtJambiObject

The QHostAddress class provides an IP address.

This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.

QHostAddress is normally used with the QTcpSocket, QTcpServer, and QUdpSocket to connect to a host or to set up a server.

A host address is set with setAddress, checked for its type using isIPv4Address() or isIPv6Address(), and retrieved with toIPv4Address, toIPv6Address, or toString.

The class also supports common predefined addresses: Null, LocalHost, LocalHostIPv6, Broadcast, and Any.

See Also:
QTcpSocket, QTcpServer, QUdpSocket

Nested Class Summary
static class QHostAddress.SpecialAddress
          Press link for info on QHostAddress.SpecialAddress
 
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
QHostAddress()
          Constructs a host address object with the IP address 0.0.0.0.
QHostAddress(int ip4Addr)
          Constructs a host address object with the IPv4 address ip4Addr.
QHostAddress(QHostAddress.SpecialAddress address)
          Constructs a QHostAddress object for address.
QHostAddress(QHostAddress copy)
          Constructs a copy of the given copy.
QHostAddress(QIPv6Address ip6Addr)
          Creates a QHostAddress from the specified ip6Addr address.
QHostAddress(java.lang.String address)
          Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1").
 
Method Summary
 void clear()
          Sets the host address to 0.0.0.0.
 boolean equals(java.lang.Object other)
          
static QHostAddress fromNativePointer(QNativePointer nativePointer)
          This function returns the QHostAddress instance pointed to by nativePointer
 int hashCode()
          
 boolean isNull()
          Returns true if this host address is null (INADDR_ANY or in6addr_any).
static QNativePointer nativePointerArray(QHostAddress[] array)
          This function returns a QNativePointer that is pointing to the specified QHostAddress array.
 QAbstractSocket.NetworkLayerProtocol protocol()
          Returns the network layer protocol of the host address.
 void readFrom(QDataStream arg__1)
          Reads a QHostAddress from arg__1.
 java.lang.String scopeId()
          Returns the scope ID of an IPv6 address.
 void setAddress(int ip4Addr)
          Set the IPv4 address specified by ip4Addr.
 void setAddress(QIPv6Address ip6Addr)
          Sets the address of this QHostAddress to ip6Addr.
 boolean setAddress(java.lang.String address)
          Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g. "127.0.0.1").
 void setScopeId(java.lang.String id)
          Sets the IPv6 scope ID of the address to id.
 int toIPv4Address()
          Returns the IPv4 address as a number.
 QIPv6Address toIPv6Address()
          Returns the IPv6 address as a Q_IPV6ADDR structure.
 java.lang.String toString()
          Returns the address as a string.
 void writeTo(QDataStream arg__1)
          Writes thisQHostAddress to arg__1.
 
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, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QHostAddress

public QHostAddress(java.lang.String address)

Constructs an IPv4 or IPv6 address based on the string address (e.g., "127.0.0.1").

See Also:
setAddress

QHostAddress

public QHostAddress(QHostAddress copy)

Constructs a copy of the given copy.


QHostAddress

public QHostAddress()

Constructs a host address object with the IP address 0.0.0.0.

See Also:
clear

QHostAddress

public QHostAddress(int ip4Addr)

Constructs a host address object with the IPv4 address ip4Addr.


QHostAddress

public QHostAddress(QIPv6Address ip6Addr)
Creates a QHostAddress from the specified ip6Addr address.


QHostAddress

public QHostAddress(QHostAddress.SpecialAddress address)

Constructs a QHostAddress object for address.

Method Detail

clear

public final void clear()

Sets the host address to 0.0.0.0.


isNull

public final boolean isNull()

Returns true if this host address is null (INADDR_ANY or in6addr_any). The default constructor creates a null address, and that address is not valid for any host or interface.


writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQHostAddress to arg__1.


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QHostAddress from arg__1.


protocol

public final QAbstractSocket.NetworkLayerProtocol protocol()

Returns the network layer protocol of the host address.


scopeId

public final java.lang.String scopeId()

Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty QString is returned.

The IPv6 scope ID specifies the scope of reachability for non-global IPv6 addresses, limiting the area in which the address can be used. All IPv6 addresses are associated with such a reachability scope. The scope ID is used to disambiguate addresses that are not guaranteed to be globally unique.

IPv6 specifies the following four levels of reachability:

When using a link-local or site-local address for IPv6 connections, you must specify the scope ID. The scope ID for a link-local address is usually the same as the interface name (e.g., "eth0", "en1") or number (e.g., "1", "2").

See Also:
setScopeId

setAddress

public final void setAddress(int ip4Addr)

Set the IPv4 address specified by ip4Addr.


setAddress

public final boolean setAddress(java.lang.String address)

Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g. "127.0.0.1"). Returns true and sets the address if the address was successfully parsed; otherwise returns false.


setAddress

public final void setAddress(QIPv6Address ip6Addr)
Sets the address of this QHostAddress to ip6Addr.


setScopeId

public final void setScopeId(java.lang.String id)

Sets the IPv6 scope ID of the address to id. If the address protocol is not IPv6, this function does nothing.

See Also:
scopeId

toIPv4Address

public final int toIPv4Address()

Returns the IPv4 address as a number.

For example, if the address is 127.0.0.1, the returned value is 2130706433 (i.e. 0x7f000001).

This value is only valid if isIp4Addr() returns true.

See Also:
toString

toIPv6Address

public final QIPv6Address toIPv6Address()

Returns the IPv6 address as a Q_IPV6ADDR structure. The structure consists of 16 unsigned characters.

    Q_IPV6ADDR addr = hostAddr.toIPv6Address();
    // addr contains 16 unsigned characters

    for (int i = 0; i < 16; ++i) {
        // process addr[i]
    }

This value is only valid if isIPv6Address() returns true.

See Also:
toString

toString

public final java.lang.String toString()

Returns the address as a string.

For example, if the address is the IPv4 address 127.0.0.1, the returned string is "127.0.0.1".

Overrides:
toString in class java.lang.Object
See Also:
toIPv4Address

fromNativePointer

public static QHostAddress fromNativePointer(QNativePointer nativePointer)
This function returns the QHostAddress instance pointed to by nativePointer

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

nativePointerArray

public static QNativePointer nativePointerArray(QHostAddress[] array)
This function returns a QNativePointer that is pointing to the specified QHostAddress array.

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

equals

public boolean equals(java.lang.Object other)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

Qt Jambi Home