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  · 

QNetworkInterface Class Reference

The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces. More...

 #include <QNetworkInterface>

Note: All functions in this class are reentrant.

This class was introduced in Qt 4.2.

Public Types

enum InterfaceFlag { IsUp, IsRunning, CanBroadcast, IsLoopBack, IsPointToPoint, CanMulticast }
flags InterfaceFlags

Public Functions

QNetworkInterface ()
QNetworkInterface ( const QNetworkInterface & other )
~QNetworkInterface ()
QList<QNetworkAddressEntry> addressEntries () const
InterfaceFlags flags () const
QString hardwareAddress () const
QString humanReadableName () const
int index () const
bool isValid () const
QString name () const
QNetworkInterface & operator= ( const QNetworkInterface & other )

Static Public Members

QList<QHostAddress> allAddresses ()
QList<QNetworkInterface> allInterfaces ()
QNetworkInterface interfaceFromIndex ( int index )
QNetworkInterface interfaceFromName ( const QString & name )

Detailed Description

The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.

QNetworkInterface represents one network interface attached to the host where the program is being run. Each network interface may contain zero or more IP addresses, each of which is optionally associated with a netmask and/or a broadcast address. The list of such trios can be obtained with addressEntries(). Alternatively, when the netmask or the broadcast addresses aren't necessary, use the allAddresses() convenience function to obtain just the IP addresses.

QNetworkInterface also reports the interface's hardware address with hardwareAddress().

Not all operating systems support reporting all features. Only the IPv4 addresses are guaranteed to be listed by this class in all platforms. In particular, IPv6 address listing is only supported on Windows XP and more recent versions, Linux, MacOS X and the BSDs.

See also QNetworkAddressEntry.

Member Type Documentation

enum QNetworkInterface::InterfaceFlag
flags QNetworkInterface::InterfaceFlags

Specifies the flags associated with this network interface. The possible values are:

ConstantValueDescription
QNetworkInterface::IsUp0x1the network interface is active
QNetworkInterface::IsRunning0x2the network interface has resources allocated
QNetworkInterface::CanBroadcast0x4the network interface works in broadcast mode
QNetworkInterface::IsLoopBack0x8the network interface is a loopback interface: that is, it's a virtual interface whose destination is the host computer itself
QNetworkInterface::IsPointToPoint0x10the network interface is a point-to-point interface: that is, there is one, single other address that can be directly reached by it.
QNetworkInterface::CanMulticast0x20the network interface supports multicasting

Note that one network interface cannot be both broadcast-based and point-to-point.

The InterfaceFlags type is a typedef for QFlags<InterfaceFlag>. It stores an OR combination of InterfaceFlag values.

Member Function Documentation

QNetworkInterface::QNetworkInterface ()

Constructs an empty network interface object.

QNetworkInterface::QNetworkInterface ( const QNetworkInterface & other )

Creates a copy of the QNetworkInterface object contained in other.

QNetworkInterface::~QNetworkInterface ()

Frees the resources associated with the QNetworkInterface object.

QList<QNetworkAddressEntry> QNetworkInterface::addressEntries () const

Returns the list of IP addresses that this interface possesses along with their associated netmasks and broadcast addresses.

If the netmask or broadcast address information is not necessary, you can call the allAddresses() function to obtain just the IP addresses.

QList<QHostAddress> QNetworkInterface::allAddresses () [static]

This convenience function returns all IP addresses found on the host machine. It is equivalent to calling addressEntries() on all the objects returned by allInterfaces() to obtain lists of QHostAddress objects then calling QHostAddress::ip() on each of these.

QList<QNetworkInterface> QNetworkInterface::allInterfaces () [static]

Returns a listing of all the network interfaces found on the host machine.

InterfaceFlags QNetworkInterface::flags () const

Returns the flags associated with this network interface.

QString QNetworkInterface::hardwareAddress () const

Returns the low-level hardware address for this interface. On Ethernet interfaces, this will be a MAC address in string representation, separated by colons.

Other interface types may have other types of hardware addresses. Implementations should not depend on this function returning a valid MAC address.

QString QNetworkInterface::humanReadableName () const

Returns the human-readable name of this network interface on Windows, such as "Local Area Connection", if the name could be determined. If it couldn't, this function returns the same as name(). The human-readable name is a name that the user can modify in the Windows Control Panel, so it may change during the execution of the program.

On Unix, this function currently always returns the same as name(), since Unix systems don't store a configuration for human-readable names.

This function was introduced in Qt 4.5.

int QNetworkInterface::index () const

Returns the interface system index, if known. This is an integer assigned by the operating system to identify this interface and it generally doesn't change. It matches the scope ID field in IPv6 addresses.

If the index isn't known, this function returns 0.

This function was introduced in Qt 4.5.

QNetworkInterface QNetworkInterface::interfaceFromIndex ( int index ) [static]

Returns a QNetworkInterface object for the interface whose internal ID is index. Network interfaces have a unique identifier called the "interface index" to distinguish it from other interfaces on the system. Often, this value is assigned progressively and interfaces being removed and then added again get a different value every time.

This index is also found in the IPv6 address' scope ID field.

QNetworkInterface QNetworkInterface::interfaceFromName ( const QString & name ) [static]

Returns a QNetworkInterface object for the interface named name. If no such interface exists, this function returns an invalid QNetworkInterface object.

See also name() and isValid().

bool QNetworkInterface::isValid () const

Returns true if this QNetworkInterface object contains valid information about a network interface.

QString QNetworkInterface::name () const

Returns the name of this network interface. On Unix systems, this is a string containing the type of the interface and optionally a sequence number, such as "eth0", "lo" or "pcn0". On Windows, it's an internal ID that cannot be changed by the user.

QNetworkInterface & QNetworkInterface::operator= ( const QNetworkInterface & other )

Copies the contents of the QNetworkInterface object contained in other into this one.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Labs au hasard

Logo

La folie est de mettre en forme le même texte

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. 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 4.7
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