Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

QHostAddress Class Reference
[QtNetwork module]

The QHostAddress class provides an IP address. More...

 #include <QHostAddress>

Public Types

  • enum SpecialAddress { Null, LocalHost, LocalHostIPv6, Broadcast, Any, AnyIPv6 }

Public Functions

Related Non-Members

  • QDataStream & operator<< ( QDataStream & out, const QHostAddress & address )
  • QDataStream & operator>> ( QDataStream & in, QHostAddress & address )

Detailed Description

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, and QUdpSocket.


Member Type Documentation

enum QHostAddress::SpecialAddress

ConstantValueDescription
QHostAddress::Null0The null address object. Equivalent to QHostAddress().
QHostAddress::LocalHost2The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1").
QHostAddress::LocalHostIPv63The IPv6 localhost address. Equivalent to QHostAddress("::1").
QHostAddress::Broadcast1The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255").
QHostAddress::Any4The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0").
QHostAddress::AnyIPv65The IPv6 any-address. Equivalent to QHostAddress("::").


Member Function Documentation

QHostAddress::QHostAddress ()

Constructs a host address object with the IP address 0.0.0.0.

See also clear().

QHostAddress::QHostAddress ( quint32 ip4Addr )

Constructs a host address object with the IPv4 address ip4Addr.

QHostAddress::QHostAddress ( quint8 * ip6Addr )

Constructs a host address object with the IPv6 address ip6Addr.

ip6Addr must be a 16-byte array in network byte order (big endian).

QHostAddress::QHostAddress ( const Q_IPV6ADDR & ip6Addr )

Constructs a host address object with the IPv6 address ip6Addr.

QHostAddress::QHostAddress ( const sockaddr * sockaddr )

Constructs an IPv4 or IPv6 address using the address specified by the native structure sockaddr.

See also setAddress().

QHostAddress::QHostAddress ( const QString & address )

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

See also setAddress().

QHostAddress::QHostAddress ( const QHostAddress & address )

Constructs a copy of the given address.

QHostAddress::QHostAddress ( SpecialAddress address )

Constructs a QHostAddress object for address.

QHostAddress::~QHostAddress ()

Destroys the host address object.

void QHostAddress::clear ()

Sets the host address to 0.0.0.0.

bool QHostAddress::isNull () const

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.

QAbstractSocket::NetworkLayerProtocol QHostAddress::protocol () const

Returns the network layer protocol of the host address.

QString QHostAddress::scopeId () const

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:

  • Node-local: Addresses that are only used for communicating with services on the same interface (e.g., the loopback interface "::1").
  • Link-local: Addresses that are local to the network interface (link). There is always one link-local address for each IPv6 interface on your host. Link-local addresses ("fe80...") are generated from the MAC address of the local network adaptor, and are not guaranteed to be unique.
  • Site-local: Addresses that are local to the site / private network (e.g., the company intranet). Site-local addresses ("fec0...") are usually distributed by the site router, and are not guaranteed to be unique outside of the local site.
  • Global: For globally routable addresses, such as public servers on the Internet.

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").

This function was introduced in Qt 4.1.

See also setScopeId().

void QHostAddress::setAddress ( quint32 ip4Addr )

Set the IPv4 address specified by ip4Addr.

void QHostAddress::setAddress ( quint8 * ip6Addr )

This is an overloaded member function, provided for convenience.

Set the IPv6 address specified by ip6Addr.

ip6Addr must be an array of 16 bytes in network byte order (high-order byte first).

void QHostAddress::setAddress ( const Q_IPV6ADDR & ip6Addr )

This is an overloaded member function, provided for convenience.

Set the IPv6 address specified by ip6Addr.

bool QHostAddress::setAddress ( const QString & address )

This is an overloaded member function, provided for convenience.

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.

void QHostAddress::setAddress ( const sockaddr * sockaddr )

This is an overloaded member function, provided for convenience.

Sets the IPv4 or IPv6 address specified by the native structure sockaddr. Returns true and sets the address if the address was successfully parsed; otherwise returns false.

void QHostAddress::setScopeId ( const QString & id )

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

This function was introduced in Qt 4.1.

See also scopeId().

quint32 QHostAddress::toIPv4Address () const

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().

Q_IPV6ADDR QHostAddress::toIPv6Address () const

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().

QString QHostAddress::toString () const

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

See also toIPv4Address().

bool QHostAddress::operator!= ( const QHostAddress & other ) const

Returns true if this host address is not the same as the other address given; otherwise returns false.

This function was introduced in Qt 4.2.

bool QHostAddress::operator!= ( SpecialAddress other ) const

This is an overloaded member function, provided for convenience.

Returns true if this host address is not the same as the other address given; otherwise returns false.

QHostAddress & QHostAddress::operator= ( const QHostAddress & address )

Assigns another host address to this object, and returns a reference to this object.

QHostAddress & QHostAddress::operator= ( const QString & address )

This is an overloaded member function, provided for convenience.

Assigns the host address address to this object, and returns a reference to this object.

See also setAddress().

bool QHostAddress::operator== ( const QHostAddress & other ) const

Returns true if this host address is the same as the other address given; otherwise returns false.

bool QHostAddress::operator== ( SpecialAddress other ) const

This is an overloaded member function, provided for convenience.

Returns true if this host address is the same as the other address given; otherwise returns false.


Related Non-Members

QDataStream & operator<< ( QDataStream & out, const QHostAddress & address )

This is an overloaded member function, provided for convenience.

Writes host address address to the stream out and returns a reference to the stream.

See also Format of the QDataStream operators.

QDataStream & operator>> ( QDataStream & in, QHostAddress & address )

This is an overloaded member function, provided for convenience.

Reads a host address into address from the stream in and returns a reference to the stream.

See also Format of the QDataStream operators.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  2. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  6. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 51
  4. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  6. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Introduction

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtextended4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web