The QMultiMap class is a convenience QMap 子類提供多值映射。 更多...
| 頭: | #include <QMultiMap> |
| 繼承: | QMap<Key, T> |
注意: 此類的所有函數 可重入 .
| QMultiMap () | |
| 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 ) |
| void | swap (QMultiMap<Key, T> & other ) |
| QMultiMap | operator+ (const QMultiMap & other ) const |
| QMultiMap & | operator+= (const QMultiMap & other ) |
The QMultiMap class is a convenience QMap 子類提供多值映射。
QMultiMap <Key, T> 是一種 Qt 一般 容器類 . 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 ().
因為 QMultiMap 繼承 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 使用 QMap 的迭代器類 (例如: QMapIterator ). But in addition, it provides an insert () function that corresponds to QMap::insertMulti (), 和 replace () function that corresponds to QMap::insert (). It also provides convenient operator+() and operator+=().
範例:
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
不像 QMap , QMultiMap provides no operator[]. Use value () 或 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 可賦值數據類型 . This covers most data types you are likely to encounter, but the compiler won't let you, for example, store a QWidget 作為值;取而代之,存儲 QWidget *. In addition, QMultiMap 's key type must provide operator<(). See the QMap 文檔編製瞭解細節。
另請參閱 QMap , QMapIterator , QMutableMapIterator ,和 QMultiHash .
Constructs an empty map.
構造副本為 other (which can be a QMap 或 QMultiMap ).
另請參閱 operator= ().
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 ().
該函數在 Qt 4.3 引入。
另請參閱 QMap::constFind ().
這是重載函數。
另請參閱 QMap::constFind ().
Returns true if the map contains an item with key key and value value ;否則返迴 false。
該函數在 Qt 4.3 引入。
另請參閱 QMap::contains ().
這是重載函數。
另請參閱 QMap::contains ().
Returns the number of items with key key and value value .
該函數在 Qt 4.3 引入。
另請參閱 QMap::count ().
這是重載函數。
另請參閱 QMap::count ().
這是重載函數。
另請參閱 QMap::count ().
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.
該函數在 Qt 4.3 引入。
另請參閱 QMap::find ().
這是重載函數。
另請參閱 QMap::find ().
這是重載函數。
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.
該函數在 Qt 4.3 引入。
另請參閱 QMap::find ().
這是重載函數。
該函數在 Qt 4.3 引入。
另請參閱 QMap::find ().
Inserts a new item with the key key 和值 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.)
另請參閱 replace ().
Removes all the items that have the key key and the value value from the map. Returns the number of items removed.
該函數在 Qt 4.3 引入。
另請參閱 QMap::remove ().
這是重載函數。
另請參閱 QMap::remove ().
Inserts a new item with the key key 和值 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 .
另請參閱 insert ().
Swaps map other with this map. This operation is very fast and never fails.
該函數在 Qt 4.8 引入。
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.
另請參閱 operator+= ().
Inserts all the items in the other map into this map and returns a reference to this map.