6.0.0-rc4Source

QMultiMap Class

template <typename K, typename V> class QMultiMap

The QMultiMap class is a template class that provides an ordered associative container with multiple values per key. More…

Header#include <QMultiMap>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
InheritsQtPrivate::AssocContainer

List of all members, including inherited members

Public Functions

QMultiMap()
QList<K>uniqueKeys() const
const K &firstKey() const
const K &lastKey() const
typename Base::iteratorlowerBound(const K &k)
typename Base::iteratorupperBound(const K &k)
typename Base::const_iteratorlowerBound(const K &k) const
typename Base::const_iteratorupperBound(const K &k) const
V &first()
const V &first() const
V &last()
const V &last() const
std::multimap<K, V>toStdMultiMap() const &
std::multimap<K, V>toStdMultiMap() &&

Detailed Description

QMultiMap<Key, T> is like QMap, but insert() always adds a new item, so several values can be stored under the same key. Items with equal keys are kept in insertion order. values(key) returns all values stored under a key, and count(key) returns how many there are.

QMultiMap<QString, int> scores;
scores.insert("Alice", 10);
scores.insert("Alice", 20);
QList<int> aliceScores = scores.values("Alice"); // {10, 20}

See also QMap and QMultiHash.

Differences from Qt

QMultiMap is implemented on top of std::multimap and is not implicitly shared. Values stored under one key are returned in insertion order, whereas Qt returns the most recently inserted first, so first() and last() return the value inserted first among those of the smallest and the largest key.

Member Function Documentation

QMultiMap::QMultiMap()

Constructs an empty multi-map.

V & QMultiMap::first()

Returns a reference to the first value, the one with the smallest key. The map must not be empty.

See also last() and firstKey().

const V & QMultiMap::first() const

This is an overloaded function.

const K & QMultiMap::firstKey() const

Returns a reference to the smallest key in the map. The map must not be empty.

See also lastKey().

V & QMultiMap::last()

Returns a reference to the last value, the one with the largest key. The map must not be empty.

See also first() and lastKey().

const V & QMultiMap::last() const

This is an overloaded function.

const K & QMultiMap::lastKey() const

Returns a reference to the largest key in the map. The map must not be empty.

See also firstKey().

typename Base::iterator QMultiMap::lowerBound(const K &k)

Returns an iterator to the first item whose key is not less than k, or end() if there is none.

See also upperBound().

typename Base::const_iterator QMultiMap::lowerBound(const K &k) const

This is an overloaded function.

Returns a const iterator to the first item whose key is not less than k, or end().

std::multimap<K, V> QMultiMap::toStdMultiMap() const &

Returns a std::multimap with the items of the map.

std::multimap<K, V> QMultiMap::toStdMultiMap() &&

This is an overloaded function.

Moves the items out of the map.

This function was introduced in 6.0.

QList<K> QMultiMap::uniqueKeys() const

Returns the keys of the map in ascending order, each key listed once even if it has several values.

typename Base::iterator QMultiMap::upperBound(const K &k)

Returns an iterator to the first item whose key is greater than k, or end() if there is none.

See also lowerBound().

typename Base::const_iterator QMultiMap::upperBound(const K &k) const

This is an overloaded function.

Returns a const iterator to the first item whose key is greater than k, or end().