QMultiHash Class ReferenceThe QMultiHash class is a convenience QHash subclass that provides multi-valued hashes. More... #include <QMultiHash> Inherits: QHash<Key, T>. Note: All functions in this class are reentrant. Public Functions
Detailed DescriptionThe 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
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Developer Network au hasard![]() Comment fermer une applicationLe 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 utilesContact
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 contacter par email ou par MP ! |
Copyright © 2000-2012 - www.developpez.com