QKeyValueIterator Class

Iterator over the key/value pairs of an associative container. More...

Header: #include <QKeyValueIterator>
qmake: QT += core
Since: Qt 5.10

This class was introduced in Qt 5.10.

Public Functions

QKeyValueIterator(Iterator o)
QKeyValueIterator()
Iterator base() const
std::pair<Key, T> operator*() const
QKeyValueIterator<Key, T, Iterator> &operator++()
QKeyValueIterator<Key, T, Iterator> operator++(int)
QKeyValueIterator<Key, T, Iterator> &operator--()
QKeyValueIterator<Key, T, Iterator> operator--(int)
bool operator!=(QKeyValueIterator<Key, T, Iterator> lhs, QKeyValueIterator<Key, T, Iterator> rhs)
bool operator==(QKeyValueIterator<Key, T, Iterator> lhs, QKeyValueIterator<Key, T, Iterator> rhs)

Detailed Description

The QKeyValueIterator class provides an STL-style iterator for returning key/value pairs from associative containers like QHash and QMap. It supports the same API as the STL associative containers, i.e. getting a key/value pair when iterating through the container.

This will allow for better interoperability between QMap, QHash and friends and STL-style algorithms.

Warning: Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read Implicit sharing iterator problem.

Member Function Documentation

QKeyValueIterator::QKeyValueIterator(Iterator o)

Constructs a QKeyValueIterator on top of o.

QKeyValueIterator::QKeyValueIterator()

Constructs a default QKeyValueIterator.

Iterator QKeyValueIterator::base() const

Returns the underlying iterator this QKeyValueIterator is based on.

std::pair<Key, T> QKeyValueIterator::operator*() const

Returns the current entry as a pair.

QKeyValueIterator<Key, T, Iterator> &QKeyValueIterator::operator++()

The prefix ++ operator (++i) advances the iterator to the next item in the container and returns the iterator.

Note: Advancing the iterator past its container's end() constitutes undefined behavior.

See also operator--().

QKeyValueIterator<Key, T, Iterator> QKeyValueIterator::operator++(int)

This is an overloaded function.

The postfix ++ operator (i++) advances the iterator to the next item in the container and returns the iterator's prior value.

Note: Advancing the iterator past its container's end() constitutes undefined behavior.

QKeyValueIterator<Key, T, Iterator> &QKeyValueIterator::operator--()

The prefix -- operator (--i) backs the iterator up to the previous item in the container and returns the iterator.

Note: Backing up an iterator to before its container's begin() constitutes undefined behavior.

See also operator++().

QKeyValueIterator<Key, T, Iterator> QKeyValueIterator::operator--(int)

This is an overloaded function.

The postfix -- operator (i--) backs the iterator up to the previous item in the container and returns the iterator's prior value.

Note: Backing up an iterator to before its container's begin() constitutes undefined behavior.

Related Non-Members

bool operator!=(QKeyValueIterator<Key, T, Iterator> lhs, QKeyValueIterator<Key, T, Iterator> rhs)

Returns true if rhs points to a different item than lhs otherwise returns false.

See also operator==().

bool operator==(QKeyValueIterator<Key, T, Iterator> lhs, QKeyValueIterator<Key, T, Iterator> rhs)

Returns true if rhs points to the same item as lhs otherwise returns false.

See also operator!=().

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.