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  · 

QMultiMap Class Reference
[QtCore module]

The QMultiMap class is a convenience QMap subclass that provides multi-valued maps. More...

 #include <QMultiMap>

Inherits QMap<Key, T>.

Note: All the functions in this class are reentrant.

Public Functions

  • QMultiMap ( const QMap<Key, T> & other )
  • QMap<Key, T>::const_iterator constFind ( const Key & key, const T & value ) const
  • QMap<Key, T>::const_iterator constFind ( const Key & key ) const
  • bool contains ( const Key & key, const T & value ) const
  • bool contains ( const Key & key ) const
  • int count ( const Key & key, const T & value ) const
  • int count ( const Key & key ) const
  • int count () const
  • QMap<Key, T>::iterator find ( const Key & key, const T & value )
  • QMap<Key, T>::iterator find ( const Key & key )
  • QMap<Key, T>::const_iterator find ( const Key & key, const T & value ) const
  • QMap<Key, T>::const_iterator find ( const Key & key ) const
  • QMap<Key, T>::iterator insert ( const Key & key, const T & value )
  • int remove ( const Key & key, const T & value )
  • int remove ( const Key & key )
  • QMap<Key, T>::iterator replace ( const Key & key, const T & value )
  • QMultiMap operator+ ( const QMultiMap & other ) const
  • QMultiMap & operator+= ( const QMultiMap & other )
  • 41 public functions inherited from QMap

Detailed Description

The QMultiMap class is a convenience QMap subclass that provides multi-valued maps.

QMultiMap<Key, T> is one of Qt's generic container classes. It inherits QMap and extends it with a few convenience functions that make it more suitable than QMap for storing multi-valued maps. A multi-valued map is a map that allows multiple values with the same key; QMap normally doesn't allow that, unless you call QMap::insertMulti().

Because QMultiMap inherits QMap, all of QMap's functionality also applies to QMultiMap. For example, you can use isEmpty() to test whether the map is empty, and you can traverse a QMultiMap using QMap's iterator classes (for example, QMapIterator). But in addition, it provides an insert() function that corresponds to QMap::insertMulti(), and a replace() function that corresponds to QMap::insert(). It also provides convenient operator+() and operator+=().

Example:

 QMultiMap<QString, int> map1, map2, map3;

 map1.insert("plenty", 100);
 map1.insert("plenty", 2000);
 // map1.size() == 2

 map2.insert("plenty", 5000);
 // map2.size() == 1

 map3 = map1 + map2;
 // map3.size() == 3

Unlike QMap, QMultiMap provides no operator[]. Use value() or replace() if you want to access the most recently inserted item with a certain key.

If you want to retrieve all the values for a single key, you can use values(const Key &key), which returns a QList<T>:

 QList<int> values = map.values("plenty");
 for (int i = 0; i < values.size(); ++i)
     cout << values.at(i) << endl;

The items that share the same key are available from most recently to least recently inserted.

If you prefer the STL-style iterators, you can call find() to get the iterator for the first item with a key and iterate from there:

 QMultiMap<QString, int>::iterator i = map.find("plenty");
 while (i != map.end() && i.key() == "plenty") {
     cout << i.value() << endl;
     ++i;
 }

QMultiMap's key and value data types must be assignable data types. This covers most data types you are likely to encounter, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QMultiMap's key type must provide operator<(). See the QMap documentation for details.

See also QMap, QMapIterator, QMutableMapIterator, and QMultiHash.


Member Function Documentation

QMultiMap::QMultiMap ()

Constructs an empty map.

QMultiMap::QMultiMap ( const QMap<Key, T> & other )

Constructs a copy of other (which can be a QMap or a QMultiMap).

See also operator=().

QMap<Key, T>::const_iterator QMultiMap::constFind ( const Key & key, const T & value ) const

Returns an iterator pointing to the item with key key and the value value in the map.

If the map contains no such item, the function returns constEnd().

This function was introduced in Qt 4.3.

See also QMap::constFind().

QMap<Key, T>::const_iterator QMultiMap::constFind ( const Key & key ) const

This is an overloaded member function, provided for convenience.

See also QMap::constFind().

bool QMultiMap::contains ( const Key & key, const T & value ) const

Returns true if the map contains an item with key key and value value; otherwise returns false.

This function was introduced in Qt 4.3.

See also QMap::contains().

bool QMultiMap::contains ( const Key & key ) const

This is an overloaded member function, provided for convenience.

See also QMap::contains().

int QMultiMap::count ( const Key & key, const T & value ) const

Returns the number of items with key key and value value.

This function was introduced in Qt 4.3.

See also QMap::count().

int QMultiMap::count ( const Key & key ) const

This is an overloaded member function, provided for convenience.

See also QMap::count().

int QMultiMap::count () const

This is an overloaded member function, provided for convenience.

See also QMap::count().

QMap<Key, T>::iterator QMultiMap::find ( const Key & key, const T & value )

Returns an iterator pointing to the item with key key and value value in the map.

If the map contains no such item, the function returns end().

If the map contains multiple items with key key, this function returns an iterator that points to the most recently inserted value.

This function was introduced in Qt 4.3.

See also QMap::find().

QMap<Key, T>::iterator QMultiMap::find ( const Key & key )

This is an overloaded member function, provided for convenience.

See also QMap::find().

QMap<Key, T>::const_iterator QMultiMap::find ( const Key & key, const T & value ) const

This is an overloaded member function, provided for convenience.

Returns a const iterator pointing to the item with the given key and value in the map.

If the map contains no such item, the function returns end().

If the map contains multiple items with the specified key, this function returns a const iterator that points to the most recently inserted value.

This function was introduced in Qt 4.3.

See also QMap::find().

QMap<Key, T>::const_iterator QMultiMap::find ( const Key & key ) const

This is an overloaded member function, provided for convenience.

This function was introduced in Qt 4.3.

See also QMap::find().

QMap<Key, T>::iterator QMultiMap::insert ( const Key & key, const T & value )

Inserts a new item with the key key and a value of value.

If there is already an item with the same key in the map, this function will simply create a new one. (This behavior is different from replace(), which overwrites the value of an existing item.)

See also replace().

int QMultiMap::remove ( const Key & key, const T & value )

Removes all the items that have the key key and the value value from the map. Returns the number of items removed.

This function was introduced in Qt 4.3.

See also QMap::remove().

int QMultiMap::remove ( const Key & key )

This is an overloaded member function, provided for convenience.

See also QMap::remove().

QMap<Key, T>::iterator QMultiMap::replace ( const Key & key, const T & value )

Inserts a new item with the key key and a value of value.

If there is already an item with the key key, that item's value is replaced with value.

If there are multiple items with the key key, the most recently inserted item's value is replaced with value.

See also insert().

QMultiMap QMultiMap::operator+ ( const QMultiMap & other ) const

Returns a map that contains all the items in this map in addition to all the items in other. If a key is common to both maps, the resulting map will contain the key multiple times.

See also operator+=().

QMultiMap & QMultiMap::operator+= ( const QMultiMap & other )

Inserts all the items in the other map into this map and returns a reference to this map.

See also insert() and operator+().

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 94
  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. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  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. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 8
Page suivante

Le Qt Labs au hasard

Logo

Utiliser OpenCL avec Qt

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