QMetaAssociation Class | Qt Core | Qt 6.11.1
Description: The QMetaAssociation class allows type erased access to associative containers.

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

# QMetaAssociation Class

The QMetaAssociation class allows type erased access to associative containers. More...

Header: | `#include <QMetaAssociation>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Since: | Qt 6.0
Inherits: | QMetaContainer

- List of all members, including inherited members

This class is equality-comparable.

## Public Types

`(since 6.11)` class | Iterable

## Public Functions

bool | canContainsKey() const
bool | canCreateConstIteratorAtKey() const
bool | canCreateIteratorAtKey() const
bool | canGetKeyAtConstIterator() const
bool | canGetKeyAtIterator() const
bool | canGetMappedAtConstIterator() const
bool | canGetMappedAtIterator() const
bool | canGetMappedAtKey() const
bool | canInsertKey() const
bool | canRemoveKey() const
bool | canSetMappedAtIterator() const
bool | canSetMappedAtKey() const
bool | containsKey(const void *container, const void *key) const
void * | createConstIteratorAtKey(const void *container, const void *key) const
void * | createIteratorAtKey(void *container, const void *key) const
void | insertKey(void *container, const void *key) const
void | keyAtConstIterator(const void *iterator, void *key) const
void | keyAtIterator(const void *iterator, void *key) const
QMetaType | keyMetaType() const
void | mappedAtConstIterator(const void *iterator, void *mapped) const
void | mappedAtIterator(const void *iterator, void *mapped) const
void | mappedAtKey(const void *container, const void *key, void *mapped) const
QMetaType | mappedMetaType() const
void | removeKey(void *container, const void *key) const
void | setMappedAtIterator(const void *iterator, const void *mapped) const
void | setMappedAtKey(void *container, const void *key, const void *mapped) const

## Static Public Members

`(since 6.0)` QMetaAssociation | fromContainer()

## Related Non-Members

bool | operator!=(const QMetaAssociation &lhs, const QMetaAssociation &rhs)
bool | operator==(const QMetaAssociation &lhs, const QMetaAssociation &rhs)

## Detailed Description

The class provides a number of primitive container operations, using void* as operands. This way, you can manipulate a generic container retrieved from a Variant without knowing its type.

QMetaAssociation covers both, containers with mapped values such as QMap or QHash, and containers that only hold keys such as QSet.

The void* arguments to the various methods are typically created by using a QVariant of the respective container or value type, and calling its QVariant::data() or QVariant::constData() methods. However, you can also pass plain pointers to objects of the container or value type.

Iterator invalidation follows the rules given by the underlying containers and is not expressed in the API. Therefore, for a truly generic container, any iterators should be considered invalid after any write operation.

See also QMetaContainer, QMetaSequence, QIterable, and QIterator.

## Member Function Documentation

### bool QMetaAssociation::canContainsKey() const

Returns `true` if the container can be queried for keys using containsKey(), otherwise returns `false`.

### bool QMetaAssociation::canCreateConstIteratorAtKey() const

Returns `true` if a const iterator pointing to an entry in the container can be created using createConstIteratorAtKey(), otherwise returns false.

### bool QMetaAssociation::canCreateIteratorAtKey() const

Returns `true` if an iterator pointing to an entry in the container can be created using createIteratorAtKey(), otherwise returns false.

See also createIteratorAtKey().

### bool QMetaAssociation::canGetKeyAtConstIterator() const

Returns `true` if a key can be retrieved from a const iterator using keyAtConstIterator(), otherwise returns `false`.

See also keyAtConstIterator().

### bool QMetaAssociation::canGetKeyAtIterator() const

Returns `true` if a key can be retrieved from a non-const iterator using keyAtIterator(), otherwise returns `false`.

See also keyAtIterator().

### bool QMetaAssociation::canGetMappedAtConstIterator() const

Returns `true` if a mapped value can be retrieved from a const iterator using mappedAtConstIterator(), otherwise returns `false`.

See also mappedAtConstIterator().

### bool QMetaAssociation::canGetMappedAtIterator() const

Returns `true` if a mapped value can be retrieved from a non-const iterator using mappedAtIterator(), otherwise returns `false`.

See also mappedAtIterator().

### bool QMetaAssociation::canGetMappedAtKey() const

Returns `true` if the container can be queried for values using mappedAtKey(), otherwise returns `false`.

### bool QMetaAssociation::canInsertKey() const

Returns `true` if keys can be added to the container using insertKey(), otherwise returns `false`.

See also insertKey().

### bool QMetaAssociation::canRemoveKey() const

Returns `true` if keys can be removed from the container using removeKey(), otherwise returns `false`.

See also removeKey().

### bool QMetaAssociation::canSetMappedAtIterator() const

Returns `true` if a mapped value can be set via a non-const iterator using setMappedAtIterator(), otherwise returns `false`.

See also setMappedAtIterator().

### bool QMetaAssociation::canSetMappedAtKey() const

Returns `true` if mapped values can be modified in the container using setMappedAtKey(), otherwise returns `false`.

See also setMappedAtKey().

### bool QMetaAssociation::containsKey(const void *container, const void *key) const

Returns `true` if the container can be queried for keys and contains the key, otherwise returns `false`.

See also canContainsKey().

### void *QMetaAssociation::createConstIteratorAtKey(const void *container, const void *key) const

Returns a const iterator pointing to the entry of key in the container, if possible. If the entry doesn't exist, creates a const iterator pointing to the end of the container. If no const iterator can be created, returns `nullptr`.

The const iterator has to be destroyed using destroyConstIterator().

See also canCreateConstIteratorAtKey(), constBegin(), constEnd(), and destroyConstIterator().

### void *QMetaAssociation::createIteratorAtKey(void *container, const void *key) const

Returns a non-const iterator pointing to the entry of key in the container, if possible. If the entry doesn't exist, creates a non-const iterator pointing to the end of the container. If no non-const iterator can be created, returns `nullptr`.

The non-const iterator has to be destroyed using destroyIterator().

See also canCreateIteratorAtKey(), begin(), end(), and destroyIterator().

### `[static constexpr, since 6.0]` template <typename T> QMetaAssociation QMetaAssociation::fromContainer()

Returns the QMetaAssociation corresponding to the type given as template parameter.

This function was introduced in Qt 6.0.

### void QMetaAssociation::insertKey(void *container, const void *key) const

Inserts the key into the container if possible. If the container has mapped values a default-create mapped value is associated with the key.

See also canInsertKey().

### void QMetaAssociation::keyAtConstIterator(const void *iterator, void *key) const

Retrieves the key pointed to by the const iterator and stores it in the memory location pointed to by key, if possible.

See also canGetKeyAtConstIterator(), constBegin(), constEnd(), and createConstIteratorAtKey().

### void QMetaAssociation::keyAtIterator(const void *iterator, void *key) const

Retrieves the key pointed to by the non-const iterator and stores it in the memory location pointed to by key, if possible.

See also canGetKeyAtIterator(), begin(), end(), and createIteratorAtKey().

### QMetaType QMetaAssociation::keyMetaType() const

Returns the meta type for keys in the container.

### void QMetaAssociation::mappedAtConstIterator(const void *iterator, void *mapped) const

Retrieves the mapped value pointed to by the const iterator and stores it in the memory location pointed to by mapped, if possible.

See also canGetMappedAtConstIterator(), constBegin(), constEnd(), and createConstIteratorAtKey().

### void QMetaAssociation::mappedAtIterator(const void *iterator, void *mapped) const

Retrieves the mapped value pointed to by the non-const iterator and stores it in the memory location pointed to by mapped, if possible.

See also setMappedAtIterator(), canGetMappedAtIterator(), begin(), end(), and createIteratorAtKey().

### void QMetaAssociation::mappedAtKey(const void *container, const void *key, void *mapped) const

Retrieves the mapped value associated with the key in the container and places it in the memory location pointed to by mapped, if that is possible.

See also setMappedAtKey() and canGetMappedAtKey().

### QMetaType QMetaAssociation::mappedMetaType() const

Returns the meta type for mapped values in the container.

### void QMetaAssociation::removeKey(void *container, const void *key) const

Removes the key and its associated mapped value from the container if possible.

See also canRemoveKey().

### void QMetaAssociation::setMappedAtIterator(const void *iterator, const void *mapped) const

Writes the mapped value to the container location pointed to by the non-const iterator, if possible.

See also mappedAtIterator(), canSetMappedAtIterator(), begin(), end(), and createIteratorAtKey().

### void QMetaAssociation::setMappedAtKey(void *container, const void *key, const void *mapped) const

Overwrites the value associated with the key in the container using the mapped value passed as argument if that is possible.

See also mappedAtKey() and canSetMappedAtKey().

## Related Non-Members

### `[noexcept]` bool operator!=(const QMetaAssociation &lhs, const QMetaAssociation &rhs)

Returns `true` if the QMetaAssociation lhs represents a different container type than the QMetaAssociation rhs, otherwise returns `false`.

### `[noexcept]` bool operator==(const QMetaAssociation &lhs, const QMetaAssociation &rhs)

Returns `true` if the QMetaAssociation lhs represents the same container type as the QMetaAssociation rhs, otherwise returns `false`.