QKeyValueIterator Class | Qt Core | Qt 6.11.1
Description: Iterator over the key/value pairs of an associative container.

- Qt 6.11
- Qt Core
- C++ Classes
- QKeyValueIterator
- Qt 6.11.1 Reference Documentation

# QKeyValueIterator Class

template <typename Key, typename T, typename Iterator, typename Traits = QtPrivate::QDefaultKeyValues<Key, T, Iterator>> class QKeyValueIterator

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

Header: | `#include <QKeyValueIterator>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`

- List of all members, including inherited members

## Public Functions

| QKeyValueIterator()
| QKeyValueIterator(Iterator o)
Iterator | base() const
std::pair<Key, T> | operator*() const
QKeyValueIterator<Key, T, Iterator, Traits> & | operator++()
QKeyValueIterator<Key, T, Iterator, Traits> | operator++(int)
QKeyValueIterator<Key, T, Iterator, Traits> & | operator--()
QKeyValueIterator<Key, T, Iterator, Traits> | operator--(int)
QKeyValueIterator<Key, T, Iterator, Traits>::pointer | operator->() const

## Related Non-Members

bool | operator!=(QKeyValueIterator<Key, T, Iterator, Traits> lhs, QKeyValueIterator<Key, T, Iterator, Traits> rhs)
bool | operator==(QKeyValueIterator<Key, T, Iterator, Traits> lhs, QKeyValueIterator<Key, T, Iterator, Traits> 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()

Constructs a default QKeyValueIterator.

### `[explicit constexpr noexcept(...)]` QKeyValueIterator::QKeyValueIterator(Iterator o)

Constructs a QKeyValueIterator on top of o.

Note: This function is noexcept when `std::is_nothrow_move_constructible<Iterator>::value` is `true`.

### 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, Traits> &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, Traits> QKeyValueIterator::operator++(int)

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.

This is an overloaded function.

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

The prefix c{–} 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, Traits> QKeyValueIterator::operator--(int)

The postfix c{–} 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.

This is an overloaded function.

### QKeyValueIterator<Key, T, Iterator, Traits>::pointer QKeyValueIterator::operator->() const

Returns the current entry as a pointer-like object to the pair.

See also operator*().

## Related Non-Members

### `[noexcept]` bool operator!=(QKeyValueIterator<Key, T, Iterator, Traits> lhs, QKeyValueIterator<Key, T, Iterator, Traits> rhs)

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

See also operator==().

### `[noexcept]` bool operator==(QKeyValueIterator<Key, T, Iterator, Traits> lhs, QKeyValueIterator<Key, T, Iterator, Traits> rhs)

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

See also operator!=().