QAssociativeIterable Class | Qt Core | Qt 6.11.1
Description: The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.

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

# QAssociativeIterable Class

The QAssociativeIterable class is an iterable interface for an associative container in a QVariant. More...

Header: | `#include <QAssociativeIterable>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Inherits: | QIterable
Status: | Until 6.15

This class is scheduled for deprecation in version 6.15.

- List of all members, including inherited members

## Public Types

| BidirectionalConstIterator
| BidirectionalIterator
| ForwardConstIterator
| ForwardIterator
| InputConstIterator
| InputIterator
| RandomAccessConstIterator
| RandomAccessIterator
`(until 6.15)` | const_iterator
`(since 6.0, until 6.15)` | iterator

## Public Functions

bool | containsKey(const QVariant &key)
QAssociativeIterable::const_iterator | find(const QVariant &key) const
void | insertKey(const QVariant &key)
QAssociativeIterable::iterator | mutableFind(const QVariant &key)
void | removeKey(const QVariant &key)
void | setValue(const QVariant &key, const QVariant &mapped)
QVariant | value(const QVariant &key) const

## Detailed Description

Use QMetaAssociation::Iterable instead.

This class allows several methods of accessing the elements of an associative container held within a QVariant. An instance of QAssociativeIterable can be extracted from a QVariant if it can be converted to a QVariantHash or QVariantMap or if a custom mutable view has been registered.

The container itself is not copied before iterating over it.

See also QVariant.

## Member Type Documentation

### `[alias]` QAssociativeIterable::BidirectionalConstIterator

Exposes a const_iterator using std::bidirectional_iterator_tag.

### `[alias]` QAssociativeIterable::BidirectionalIterator

Exposes an iterator using std::bidirectional_iterator_tag.

### `[alias]` QAssociativeIterable::ForwardConstIterator

Exposes a const_iterator using std::forward_iterator_tag.

### `[alias]` QAssociativeIterable::ForwardIterator

Exposes an iterator using std::forward_iterator_tag.

### `[alias]` QAssociativeIterable::InputConstIterator

Exposes a const_iterator using std::input_iterator_tag.

### `[alias]` QAssociativeIterable::InputIterator

Exposes an iterator using std::input_iterator_tag.

### `[alias]` QAssociativeIterable::RandomAccessConstIterator

Exposes a const_iterator using std::random_access_iterator_tag.

### `[alias]` QAssociativeIterable::RandomAccessIterator

Exposes an iterator using std::random_access_iterator_tag.

### `[alias, until 6.15]` QAssociativeIterable::const_iterator

This typedef is scheduled for deprecation in version 6.15.

Use QMetaAssociation::Iterable::ConstIterator instead.

The QAssociativeIterable::const_iterator allows iteration over a container in a QVariant.

A QAssociativeIterable::const_iterator can only be created by a QAssociativeIterable instance, and can be used in a way similar to other stl-style iterators.

See also QAssociativeIterable.

### `[alias, since 6.0, until 6.15]` QAssociativeIterable::iterator

This typedef is scheduled for deprecation in version 6.15.

Use QMetaAssociation::Iterable::Iterator instead.

The QAssociativeIterable::iterator allows iteration over a container in a QVariant.

A QAssociativeIterable::iterator can only be created by a QAssociativeIterable instance, and can be used in a way similar to other stl-style iterators.

This typedef was introduced in Qt 6.0.

See also QAssociativeIterable.

## Member Function Documentation

### bool QAssociativeIterable::containsKey(const QVariant &key)

Returns `true` if the container has an entry with the given key, or `false` otherwise. If the key isn't convertible to the expected type, `false` is returned.

### QAssociativeIterable::const_iterator QAssociativeIterable::find(const QVariant &key) const

Retrieves a const_iterator pointing to the element at the given key, or the end of the container if that key does not exist. If the key isn't convertible to the expected type, the end of the container is returned.

### void QAssociativeIterable::insertKey(const QVariant &key)

Inserts a new entry with the given key, or resets the mapped value of any existing entry with the given key to the default constructed mapped value. The key is coerced to the expected type: If it isn't convertible, a default value is inserted.

### QAssociativeIterable::iterator QAssociativeIterable::mutableFind(const QVariant &key)

Retrieves an iterator pointing to the element at the given key, or the end of the container if that key does not exist. If the key isn't convertible to the expected type, the end of the container is returned.

### void QAssociativeIterable::removeKey(const QVariant &key)

Removes the entry with the given key from the container. The key is coerced to the expected type: If it isn't convertible, the default value is removed.

### void QAssociativeIterable::setValue(const QVariant &key, const QVariant &mapped)

Sets the mapped value associated with key to mapped, if possible. Inserts a new entry if none exists yet, for the given key. If the key is not convertible to the key type, the value for the default-constructed key type is overwritten.

See also value().

### QVariant QAssociativeIterable::value(const QVariant &key) const

Retrieves the mapped value at the given key, or a default-constructed QVariant of the mapped type, if the key does not exist. If the key is not convertible to the key type, the mapped value associated with the default-constructed key is returned.

See also setValue().