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  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QMultiHash Class Reference
[QtCore module]

The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes. More...

 #include <QMultiHash>

Inherits QHash<Key, T>.

Note: All the functions in this class are reentrant.

Public Functions

  • QMultiHash ( const QHash<Key, T> & other )
  • QHash<Key, T>::const_iterator constFind ( const Key & key, const T & value ) const
  • QHash<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
  • QHash<Key, T>::iterator find ( const Key & key, const T & value )
  • QHash<Key, T>::iterator find ( const Key & key )
  • QHash<Key, T>::const_iterator find ( const Key & key, const T & value ) const
  • QHash<Key, T>::const_iterator find ( const Key & key ) const
  • QHash<Key, T>::iterator insert ( const Key & key, const T & value )
  • int remove ( const Key & key, const T & value )
  • int remove ( const Key & key )
  • QHash<Key, T>::iterator replace ( const Key & key, const T & value )
  • QMultiHash operator+ ( const QMultiHash & other ) const
  • QMultiHash & operator+= ( const QMultiHash & other )
  • 39 public functions inherited from QHash

Detailed Description

The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.

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

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

Example:

 QMultiHash<QString, int> hash1, hash2, hash3;

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

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

 hash3 = hash1 + hash2;
 // hash3.size() == 3

Unlike QHash, QMultiHash 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 = hash.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.

A more efficient approach is to call find() to get the STL-style iterator for the first item with a key and iterate from there:

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

QMultiHash's key and value data types must be assignable data types. You cannot, for example, store a QWidget as a value; instead, store a QWidget *. In addition, QMultiHash's key type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type. See the QHash documentation for details.

See also QHash, QHashIterator, QMutableHashIterator, and QMultiMap.


Member Function Documentation

QMultiHash::QMultiHash ()

Constructs an empty hash.

QMultiHash::QMultiHash ( const QHash<Key, T> & other )

Constructs a copy of other (which can be a QHash or a QMultiHash).

See also operator=().

QHash<Key, T>::const_iterator QMultiHash::constFind ( const Key & key, const T & value ) const

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

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

This function was introduced in Qt 4.3.

See also QHash::constFind().

QHash<Key, T>::const_iterator QMultiHash::constFind ( const Key & key ) const

This is an overloaded member function, provided for convenience.

See also QHash::constFind().

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

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

This function was introduced in Qt 4.3.

See also QHash::contains().

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

This is an overloaded member function, provided for convenience.

See also QHash::contains().

int QMultiHash::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 QHash::count().

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

This is an overloaded member function, provided for convenience.

See also QHash::count().

int QMultiHash::count () const

This is an overloaded member function, provided for convenience.

See also QHash::count().

QHash<Key, T>::iterator QMultiHash::find ( const Key & key, const T & value )

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

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

If the hash 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 QHash::find().

QHash<Key, T>::iterator QMultiHash::find ( const Key & key )

This is an overloaded member function, provided for convenience.

See also QHash::find().

QHash<Key, T>::const_iterator QMultiHash::find ( const Key & key, const T & value ) const

This is an overloaded member function, provided for convenience.

This function was introduced in Qt 4.3.

QHash<Key, T>::const_iterator QMultiHash::find ( const Key & key ) const

This is an overloaded member function, provided for convenience.

See also QHash::find().

QHash<Key, T>::iterator QMultiHash::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 hash, 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 QMultiHash::remove ( const Key & key, const T & value )

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

This function was introduced in Qt 4.3.

See also QHash::remove().

int QMultiHash::remove ( const Key & key )

This is an overloaded member function, provided for convenience.

See also QHash::remove().

QHash<Key, T>::iterator QMultiHash::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().

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

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

See also operator+=().

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

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

See also insert().

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

Le Qt Quarterly au hasard

Logo

Le repérage des paires de parenthèses avec QSyntaxHighlighter

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. 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.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