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  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QPair Class Reference
[QtCore module]

The QPair class is a template class that stores a pair of items. More...

 #include <QPair>

Public Types

Public Functions

  • QPair ( const T1 & value1, const T2 & value2 )
  • QPair<T1, T2> & operator= ( const QPair<T1, T2> & other )

Public Variables

Related Non-Members

  • QPair<T1, T2> qMakePair ( const T1 & value1, const T2 & value2 )
  • bool operator!= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • bool operator< ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • QDataStream & operator<< ( QDataStream & out, const QPair<T1, T2> & pair )
  • bool operator<= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • bool operator== ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • bool operator> ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • bool operator>= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )
  • QDataStream & operator>> ( QDataStream & in, QPair<T1, T2> & pair )

Detailed Description

The QPair class is a template class that stores a pair of items.

QPair<T1, T2> can be used in your application if the STL pair type is not available. It stores one value of type T1 and one value of type T2. It can be used as a return value for a function that needs to return two values, or as the value type of a generic container.

Here's an example of a QPair that stores one QString and one double value:

 QPair<QString, double> pair;

The components are accessible as public data members called first and second. For example:

 pair.first = "pi";
 pair.second = 3.14159265358979323846;

QPair's template data types (T1 and T2) must be assignable data types. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; these requirements are documented on a per-function basis.

See also Generic Containers.


Member Type Documentation

typedef QPair::first_type

The type of the first element in the pair (T1).

See also first.

typedef QPair::second_type

The type of the second element in the pair (T2).

See also second.


Member Function Documentation

QPair::QPair ()

Constructs an empty pair. The first and second elements are initialized with default-constructed values.

QPair::QPair ( const T1 & value1, const T2 & value2 )

Constructs a pair and initializes the first element with value1 and the second element with value2.

See also qMakePair().

QPair<T1, T2> & QPair::operator= ( const QPair<T1, T2> & other )

Assigns other to this pair.


Member Variable Documentation

T1 QPair::first

The first element in the pair.

T2 QPair::second

The second element in the pair.


Related Non-Members

QPair<T1, T2> qMakePair ( const T1 & value1, const T2 & value2 )

Returns a QPair<T1, T2> that contains value1 and value2. Example:

 QList<QPair<int, double> > list;
 list.append(qMakePair(66, 3.14159));

This is equivalent to QPair<T1, T2>(value1, value2), but usually requires less typing.

bool operator!= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is not equal to p2; otherwise returns false. Two pairs compare as not equal if their first data members are not equal or if their second data members are not equal.

This function requires the T1 and T2 types to have an implementation of operator==().

bool operator< ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is less than p2; otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<().

QDataStream & operator<< ( QDataStream & out, const QPair<T1, T2> & pair )

This is an overloaded member function, provided for convenience.

Writes the pair pair to stream out.

This function requires the T1 and T2 types to implement operator<<().

See also Format of the QDataStream operators.

bool operator<= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is less than or equal to p2; otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<().

bool operator== ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is equal to p2; otherwise returns false. Two pairs compare equal if their first data members compare equal and if their second data members compare equal.

This function requires the T1 and T2 types to have an implementation of operator==().

bool operator> ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is greater than p2; otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<().

bool operator>= ( const QPair<T1, T2> & p1, const QPair<T1, T2> & p2 )

This is an overloaded member function, provided for convenience.

Returns true if p1 is greater than or equal to p2; otherwise returns false. The comparison is done on the first members of p1 and p2; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<().

QDataStream & operator>> ( QDataStream & in, QPair<T1, T2> & pair )

This is an overloaded member function, provided for convenience.

Reads a pair from stream in into pair.

This function requires the T1 and T2 types to implement operator>>().

See also Format of the QDataStream operators.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  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. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  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. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

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