CopperSpice API  1.7.2
QMap< Key, Val, C > Class Template Reference

Template class which provides a sorted container of keys and values. More...

Classes

class  const_iterator
 STL style const iterator for QMap More...
 
class  iterator
 STL style iterator for QMap More...
 

Public Typedefs

using allocator_type = typename std::map< Key, Val, C >::allocator_type
 
using const_pointer = const Val *
 
using const_reference = const Val &
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using difference_type = typename std::map< Key, Val, C >::difference_type
 
using key_compare = typename std::map< Key, Val, C >::key_compare
 
using key_type = typename std::map< Key, Val, C >::key_type
 
using mapped_type = typename std::map< Key, Val, C >::mapped_type
 
using pointer = Val *
 
using reference = Val &
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using size_type = typename std::map< Key, Val, C >::difference_type
 
using value_type = Val
 

Public Methods

 QMap () = default
 
 QMap (C compare)
 
 QMap (const QMap< Key, Val, C > &other) = default
 
 QMap (const std::map< Key, Val, C > &other)
 
template<typename Input_Iterator >
 QMap (Input_Iterator first, Input_Iterator last, const C &compare=C ())
 
 QMap (QMap< Key, Val, C > &&other) = default
 
 QMap (std::initializer_list< std::pair< const Key, Val >> list, const C &compare=C ())
 
 ~QMap () = default
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear ()
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
const_iterator constFind (const Key &key) const
 
bool contains (const Key &key) const
 
size_type count () const
 
size_type count (const Key &key) const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
QPair< iterator, iteratorequal_range (const Key &key)
 
QPair< const_iterator, const_iteratorequal_range (const Key &key) const
 
iterator erase (const_iterator iter)
 
iterator find (const Key &key)
 
const_iterator find (const Key &key) const
 
Val & first ()
 
const Val & first () const
 
const Key & firstKey () const
 
iterator insert (const Key &key, const Val &value)
 
iterator insert (const std::pair< const Key, Val > &data)
 
iterator insert (const_iterator hint, const Key &key, const Val &value)
 
bool isEmpty () const
 
const Key key (const Val &value, const Key &defaultKey=Key ()) const
 
QList< Key > keys () const
 
QList< Key > keys (const Val &value) const
 
Val & last ()
 
const Val & last () const
 
const Key & lastKey () const
 
iterator lowerBound (const Key &key)
 
const_iterator lowerBound (const Key &key) const
 
bool operator!= (const QMap< Key, Val, C > &other) const
 
QMap< Key, Val, C > & operator= (const QMap< Key, Val, C > &other) = default
 
QMap< Key, Val, C > & operator= (QMap< Key, Val, C > &&other) = default
 
bool operator== (const QMap< Key, Val, C > &other) const
 
Val & operator[] (const Key &key)
 
const Val operator[] (const Key &key) const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
size_type remove (const Key &key)
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
size_type size () const
 
void swap (QMap< Key, Val, C > &other)
 
Val take (const Key &key)
 
std::map< Key, Val, C > toStdMap () const
 
QList< Key > uniqueKeys () const
 
QMap< Key, Val, C > & unite (const QMap< Key, Val, C > &other)
 
iterator upperBound (const Key &key)
 
const_iterator upperBound (const Key &key) const
 
const Val value (const Key &key, const Val &defaultValue) const
 
QList< Val > values () const
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &out, const QMap< Key, Val, C > &map)
 
QDataStreamoperator>> (QDataStream &in, QMap< Key, Val, C > &map)
 

Detailed Description

template<typename Key, typename Val, typename C>
class QMap< Key, Val, C >

The QMap class is a template class which provides a sorted container of keys and values. This container stores the key and value as a pair. For a given key there is one corresponding value.

  • Elements in a QMap are sorted by key, elements in a QHash are in an arbitrary order/li>
  • QHash provides faster lookups than a QMap or a QFlatMap
  • QHash class requires the type for key provide an operator==() method and a global qHash(key) function
  • QMap class requires the type for key provide an operator<() method
  • Use QFlatMap when your data set is relatively small

For an overview and comparison of all containers, refer to the documentation for Container Classes. Refer to the section on Time Complexity for a discussion about which operations will be relatively faster or slower for a given container with a size of n.

Constructors

The following code is a simple example showing how to declare a QMap.

QMap<QString, int> map; // stores QString key and int values

Accessing Elements

To insert a (key, value) pair into the map use operator[]. This example inserts the following three (key, value) pairs into the QMap: ("one", 1), ("three", 3), and ("seven", 7).

map["one"] = 1;
map["three"] = 3;
map["seven"] = 7;

Another way to insert items into the map is with the insert() method.

map.insert("twelve", 12);

The following are examples to look up a value using the operator[] or value() methods.

int num1 = map["thirteen"]; // if the key is not present ("thirteen", 0) will be inserted
int num2 = map.value("thirteen");

If you want to check whether the map contains a certain key use contains().

int timeout = 30;
if (map.contains("TIMEOUT")) {
timeout = map.value("TIMEOUT");
}

There is also an overload value() method which uses the second argument as a default value if there is no item with the specified key.

int timeout = map.value("TIMEOUT", 30);

Basic Operations

Items can be removed from the map in several ways. One way is to call remove() which will remove any item with the given key. The entire map can be cleared using the clear() method.

Implicit Insert

The following code looks like operator[] is doing a look up. There is a side effect of using this method. If the key is not found then an implicit insert will occur and a (key, value) pair is added. The value in the pair is value initialized.

If this is not want you intended, replace map[i] with map.value(i).

for (int i = 0; i < 1000; ++i) {
if (map[i] == okButton) {
cout << "Found button with key " << i << endl;
}
}

Iterators

To navigate through all (key, value) pairs stored in a QMap use an iterator. QMap provides both Java style iterators (QMapIterator and QMutableMapIterator) and STL style iterators (QMap::const_iterator and QMap::iterator).

The following shows how to iterate over a QMap<QString, int> using a Java style iterator.

while (iter.hasNext()) {
iter.next();
cout << iter.key() << ": " << iter.value() << endl;
}

Here is the same code using an STL style iterator.

while (iter != map.constEnd()) {
cout << iter.key() << ": " << iter.value() << endl;
++iter;
}

The items are traversed in ascending key order. QMap allows only one value per key. If you call insert() with a key which already exists in the QMap, the previous value will be replaced with the new value.

map.insert("plenty", 100);
map.insert("plenty", 2000); // map.value("plenty") will equal 2000

To extract the values from a map and not the keys, use a "range based for loop".

for (int value : map) {
cout << value << endl;
}

Constraints on type T

The QMap<Key, Val, C> should be Default Constructible and Copy Constructible to work with all methods of this class. Data types like QObject are not copy constructible and therefore should never be stored in a container. You can however use a pointer to a QObject or any subclass as the type T.

The QMap key type must provide operator<(). QMap uses the comparison operator to sort. Two keys x and y are equal if "x is not less than y" and "y is not less than x".

Using a class as a Key

This is an example which shows how to declare a class which can be used as the key in a QMap. The employee class operator<() function will be used by QMap when keys are compared. If two employee;s have the same name then the dates of birth are used to break the tie.

class Employee
{
public:
Employee() = default;
Employee(const QString &name, const QDate &dateOfBirth);
private:
QString myName;
QDate myDateOfBirth;
};
bool operator<(const Employee &e1, const Employee &e2) {
if (e1.name() != e2.name()) {
return e1.name() < e2.name();
}
return e1.dateOfBirth() < e2.dateOfBirth();
}
// example

Overriding Sort Order

The third template parameter in QMap<Key, Val, C> is used to define a sort order for elements in the container. This parameter is optional and only needed to over ride the default behavior.

The following code is the default Compare template. You do not need to do anything for this template to be called.

template <class Key>
class qMapCompare
{
public:
bool operator()(const Key &a, const Key &b) const {
return qMapLessThanKey(a, b);
}
};

To change the behavior and sort your QMap differently you must create a new class, struct, or use a lambda expression as the third parameter. The following examples are declarations for QMap with a custom sort order.

// example 1
// example 2
auto myReverseSort = [] (auto a, auto b) { return a > b; };
QMap<Key, Val, decltype(myReverseSort)> myMapB;

The following is an example of a user defined compare class which provides "case insensitive" sorting.

class CompareIgnoreCase
{
public:
bool operator()(const QString &a, const QString &b) const {
return a.compare(b, Qt::CaseInsensitive) < 0;
}
};
See also
QFlatMap, QMultiMap, QSet

Member Typedef Documentation

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::allocator_type

Typedef for allocator used by the container.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::const_pointer

Typedef for const Val *.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::const_reference

Typedef for const Val &.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::const_reverse_iterator

Typedef for an STL style const reverse iterator.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::difference_type

Typedef for integral type used to represent the distance between two elements.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::key_compare

Typedef for the key lessthan comparison object type.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::key_type

Typedef for Key.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::mapped_type

Typedef for Val.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::pointer

Typedef for Val *.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::reference

Typedef for Val &.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::reverse_iterator

Typedef for an STL style reverse iterator.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::size_type

Typedef for a signed integer of the appropriate size for your platform.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::value_type

Typedef for Val.

Constructor & Destructor Documentation

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( )
default

Constructs an empty QMap.

See also
clear()
template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( const QMap< Key, Val, C > &  other)
default

Constructs a copy of other.

See also
operator=()
template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( QMap< Key, Val, C > &&  other)
default

Move constructs a map from other.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( std::initializer_list< std::pair< const Key, Val >>  list,
const C &  compare = C() 
)
inline

Constructs a map with a copy of each of the elements in the specified initializer list list.

If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( compare)
inlineexplicit

Constructs an empty map using the specified function object compare. Refer to Overriding Sort Order for more information about this parameter.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::QMap ( const std::map< Key, Val, C > &  other)
inlineexplicit

Constructs a copy of other.

See also
toStdMap()
template<typename Key , typename Val , typename C >
template<typename Input_Iterator >
QMap< Key, Val, C >::QMap ( Input_Iterator  first,
Input_Iterator  last,
const C &  compare = C() 
)
inline

Constructs a map containing copies of the elements between first and last.

If the function object compare is passed it will be called when sorting keys in the container. Refer to Overriding Sort Order for more information about this template parameter.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C >::~QMap ( )
default

Destroys the map. References to the values in the map and all iterators over this map become invalid.

Method Documentation

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::begin ( )
inline

Returns an STL style iterator pointing to the first item in the map.

See also
constBegin(), end()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::begin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the map.

template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::cbegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the map.

See also
begin(), cend()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::cend ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the map.

See also
cbegin(), end()
template<typename Key , typename Val , typename C >
void QMap< Key, Val, C >::clear ( )
inline

Removes all items from the map.

See also
remove()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::constBegin ( ) const
inline

Returns a const STL style iterator pointing to the first item in the map.

See also
begin(), constEnd()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::constEnd ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the map.

See also
constBegin(), end()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::constFind ( const Key &  key) const
inline

Returns a const iterator pointing to the item with the given key. If the map contains no item with key, the method returns constEnd().

See also
find(), constFind()
template<typename Key , typename Val , typename C >
bool QMap< Key, Val, C >::contains ( const Key &  key) const
inline

Returns true if the map contains an item the given key, otherwise it returns false.

See also
count()
template<typename Key , typename Val , typename C >
size_type QMap< Key, Val, C >::count ( ) const
inline

Equivalent to calling size().

template<typename Key , typename Val , typename C >
size_type QMap< Key, Val, C >::count ( const Key &  key) const
inline

Returns the number of items associated with the specified key.

See also
contains()
template<typename Key , typename Val , typename C >
const_reverse_iterator QMap< Key, Val, C >::crbegin ( ) const
inline

Returns a const STL-style reverse iterator pointing to the first item in the map, in reverse order.

See also
begin(), rbegin(), rend()
template<typename Key , typename Val , typename C >
const_reverse_iterator QMap< Key, Val, C >::crend ( ) const
inline

Returns a const STL style reverse iterator pointing to one past the last item in the map, in reverse order.

See also
end(), rend(), rbegin()
template<typename Key , typename Val , typename C >
bool QMap< Key, Val, C >::empty ( ) const
inline

This method is equivalent to isEmpty(), returning true if the map is empty, otherwise returning false.

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::end ( )
inline

Returns an STL style iterator pointing to the imaginary item after the last item in the map.

See also
begin(), constEnd()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::end ( ) const
inline

Returns a const STL style iterator pointing to the imaginary item after the last item in the map.

template<typename Key , typename Val , typename C >
QPair< iterator, iterator > QMap< Key, Val, C >::equal_range ( const Key &  key)
inline

Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().

template<typename Key , typename Val , typename C >
QPair< const_iterator, const_iterator > QMap< Key, Val, C >::equal_range ( const Key &  key) const
inline

Returns a pair of iterators corresponding to the range of items [first, second) which have the given key. If the range is empty then both iterators will be equal to end().

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::erase ( const_iterator  iter)
inline

Removes the (key, value) pair pointed to by the iterator iter from the map and returns an iterator to the next item in the map.

This method assumes the iterator is valid and refers to an element in the map. It will not check if iter points past the end of the map or is equal to the end() iterator.

See also
remove()
template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::find ( const Key &  key)
inline

Returns an iterator pointing to the item with the specified key. If the map contains no item with this key, the method returns end().

See also
constFind(), value(), values(), lowerBound(), upperBound()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::find ( const Key &  key) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
Val & QMap< Key, Val, C >::first ( )
inline

Returns a reference to the first value in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Val & QMap< Key, Val, C >::first ( ) const
inline

Returns a const reference to the first value in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Key & QMap< Key, Val, C >::firstKey ( ) const
inline

Returns a const reference to the first key in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::insert ( const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the key and value. If there is already an item with this key, the value for the item is replaced with value. This is the same behavior as insert_or_assign() in std::map.

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::insert ( const std::pair< const Key, Val > &  data)
inline

Inserts a new item with key and value from data, which is an std::pair. If there is already an item with this key, the value for the item is replaced with value.

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::insert ( const_iterator  hint,
const Key &  key,
const Val &  value 
)
inline

Inserts a new item with the key and value using hint as a suggestion about where to insert. If there is already an item with the specified key, the item's value is replaced with value.

template<typename Key , typename Val , typename C >
bool QMap< Key, Val, C >::isEmpty ( ) const
inline

Returns true if the map contains no items, otherwise returns false.

See also
size()
template<class Key , class Val , class C >
const Key QMap< Key, Val, C >::key ( const Val &  value,
const Key &  defaultKey = Key() 
) const

Returns the first key with value. If the map contains no item with value then defaultKey is returned.

This method can be slow (linear time), because the internal data structure is optimized for fast lookup by key, not by value.

See also
value(), keys()
template<typename Key , typename Val , typename C >
QList< Key > QMap< Key, Val, C >::keys ( ) const

Returns a list containing all the keys in the map in ascending order. To obtain a list of unique keys where each key from the map only occurs once, use uniqueKeys(). The order is guaranteed to be the same as returned by values().

See also
uniqueKeys(), values(), key()
template<class Key , class Val , class C >
QList< Key > QMap< Key, Val, C >::keys ( const Val &  value) const

Returns a list containing all the keys associated with specified value in ascending order.

This method can be slow (linear time), because QMap's internal data structure is optimized for fast lookup by key, not by value.

template<typename Key , typename Val , typename C >
Val & QMap< Key, Val, C >::last ( )
inline

Returns a reference to the last value in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Val & QMap< Key, Val, C >::last ( ) const
inline

Returns a const reference to the last value in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
const Key & QMap< Key, Val, C >::lastKey ( ) const
inline

Returns a const reference to the last key in the map. This method assumes the map is not empty.

template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::lowerBound ( const Key &  key)
inline

Returns an iterator pointing to the first item with the given key. If the map contains no item with key, the method returns an iterator to the nearest item with a greater key.

Example:

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.lowerBound(0); // returns iterator to (1, "one")
map.lowerBound(1); // returns iterator to (1, "one")
map.lowerBound(2); // returns iterator to (5, "five")
map.lowerBound(10); // returns iterator to (10, "ten")
map.lowerBound(999); // returns end()
See also
qLowerBound(), upperBound(), find()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::lowerBound ( const Key &  key) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
bool QMap< Key, Val, C >::operator!= ( const QMap< Key, Val, C > &  other) const
inline

Returns true if other is not equal to this map, otherwise returns false. Two maps are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator==()
template<typename Key , typename Val , typename C >
QMap< Key, Val, C > & QMap< Key, Val, C >::operator= ( const QMap< Key, Val, C > &  other)
default

Copy assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename C >
QMap< Key, Val, C > & QMap< Key, Val, C >::operator= ( QMap< Key, Val, C > &&  other)
default

Move assigns from other and returns a reference to this object.

template<typename Key , typename Val , typename C >
bool QMap< Key, Val, C >::operator== ( const QMap< Key, Val, C > &  other) const
inline

Returns true if other is equal to this map, otherwise returns false. Two maps are considered equal if they contain the same (key, value) pairs.

This method requires the type T to support operator==().

See also
operator!=()
template<class Key , class Val , class C >
Val & QMap< Key, Val, C >::operator[] ( const Key &  key)

Returns a reference to the value for the element with the given key.

If the map contains no item this the key, this method inserts a new value initialized object. A reference to the new element will be returned. Refer to default constructed elements for additional information.

See also
insert(), value()
template<class Key , class Val , class C >
const Val QMap< Key, Val, C >::operator[] ( const Key &  key) const

Returns a copy of the value for the element with the given key.

If the map contains no item with key, this method will return a value initialized object. Refer to default constructed elements for additional information.

See also
insert(), value()
template<typename Key , typename Val , typename C >
reverse_iterator QMap< Key, Val, C >::rbegin ( )
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
const_reverse_iterator QMap< Key, Val, C >::rbegin ( ) const
inline

Returns a STL style reverse iterator pointing to the first item in the map, in reverse order.

See also
begin(), crbegin(), rend()
template<typename Key , typename Val , typename C >
size_type QMap< Key, Val, C >::remove ( const Key &  key)
inline

Removes the item which has the given key. Returns the number of items removed which is either zero or one,

See also
clear(), take()
template<typename Key , typename Val , typename C >
reverse_iterator QMap< Key, Val, C >::rend ( )
inline

Returns a STL style reverse iterator pointing to one past the last item in the map, in reverse order.

See also
end(), crend(), rbegin()
template<typename Key , typename Val , typename C >
const_reverse_iterator QMap< Key, Val, C >::rend ( ) const
inline

This is an overloaded method.

template<typename Key , typename Val , typename C >
size_type QMap< Key, Val, C >::size ( ) const
inline

Returns the number of (key, value) pairs in the map.

See also
isEmpty(), count()
template<typename Key , typename Val , typename C >
void QMap< Key, Val, C >::swap ( QMap< Key, Val, C > &  other)
inline

Swaps other with this map. This operation is very fast and never fails.

template<typename Key , typename Val , typename C >
Val QMap< Key, Val, C >::take ( const Key &  key)
inline

Removes the item with the given key and returns the value associated with it. If you are not using the return value calling remove() will be more efficient.

If the item does not exist in the map, this method will return a value initialized object. Refer to default constructed elements for additional information.

See also
remove()
template<typename Key , typename Val , typename C >
std::map< Key, Val, C > QMap< Key, Val, C >::toStdMap ( ) const

Returns an STL map equivalent to this QMap.

template<typename Key , typename Val , typename C >
QList< Key > QMap< Key, Val, C >::uniqueKeys ( ) const

Returns a list of every key in the map with out duplicates.

See also
keys()
template<typename Key , typename Val , typename C >
QMap< Key, Val, C > & QMap< Key, Val, C >::unite ( const QMap< Key, Val, C > &  other)
inline

Inserts all the items in the other map into this map. If a key is common to both maps the resulting map will contain the old value.

See also
QMultiMap::insertMulti()
template<typename Key , typename Val , typename C >
iterator QMap< Key, Val, C >::upperBound ( const Key &  key)
inline

Returns an iterator pointing to the item which immediately follows the last item with specified key. If the map contains no item with specified key, the method returns an iterator to the nearest item with a greater key.

map.insert(1, "one");
map.insert(5, "five");
map.insert(10, "ten");
map.upperBound(0); // returns iterator to (1, "one")
map.upperBound(1); // returns iterator to (5, "five")
map.upperBound(2); // returns iterator to (5, "five")
map.upperBound(10); // returns end()
map.upperBound(999); // returns end()
See also
qUpperBound(), lowerBound(), find()
template<typename Key , typename Val , typename C >
const_iterator QMap< Key, Val, C >::upperBound ( const Key &  key) const
inline

This is an overloaded method.

template<class Key , class Val , class C >
const Val QMap< Key, Val, C >::value ( const Key &  key,
const Val &  defaultValue 
) const

Returns the value associated with the specified key. If the map contains no element with the given key, then defaultValue is returned.

If no default value is passed, this method will return a value initialized object. Refer to default constructed elements for additional information.

See also
key(), values(), contains(), operator[]()
template<typename Key , typename Val , typename C >
QList< Val > QMap< Key, Val, C >::values ( ) const

Returns a list containing all the values in the map in ascending order of their keys.

See also
keys(), value()

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream out,
const QMap< Key, Val, C > &  map 
)
related

Writes the given map to stream out. This method requires the types Key and Val to support operator<<().

Refer to Serializing Data Types for additional information.

QDataStream & operator>> ( QDataStream in,
QMap< Key, Val, C > &  map 
)
related

Reads a map from stream in into map. This method requires the types Key and Val to support operator>>().

Refer to Serializing Data Types for additional information.