QMetaAssociation::Iterable Class
class QMetaAssociation::IterableQMetaAssociation::Iterable is an iterable interface for an associative container in a QVariant. More...
This class was introduced in Qt 6.11.
Public Types
(since 6.11) class | ConstIterator |
(since 6.11) class | Iterator |
| BidirectionalConstIterator | |
| BidirectionalIterator | |
| ForwardConstIterator | |
| ForwardIterator | |
| InputConstIterator | |
| InputIterator | |
| RandomAccessConstIterator | |
| RandomAccessIterator |
Public Functions
| bool | containsKey(const QVariant &key) const |
| QMetaAssociation::Iterable::ConstIterator | find(const QVariant &key) const |
| void | insertKey(const QVariant &key) |
| QMetaAssociation::Iterable::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
This class allows several methods of accessing the elements of an associative container held within a QVariant. An instance of QMetaAssociation::Iterable 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.
QHash<int, QString> mapping; mapping.insert(7, "Seven"); mapping.insert(11, "Eleven"); mapping.insert(42, "Forty-two"); QVariant variant = QVariant::fromValue(mapping); if (variant.canConvert<QVariantHash>()) { QMetaAssociation::Iterable iterable = variant.value<QMetaAssociation::Iterable>(); // Can use C++11 range-for over the values: for (const QVariant &v : iterable) { qDebug() << v; } // Can use iterators: QMetaAssociation::Iterable::const_iterator it = iterable.begin(); const QMetaAssociation::Iterable::const_iterator end = iterable.end(); for ( ; it != end; ++it) { qDebug() << *it; // The current value qDebug() << it.key(); qDebug() << it.value(); } }
The container itself is not copied before iterating over it.
See also QVariant.
Member Type Documentation
[alias] Iterable::BidirectionalConstIterator
Exposes a const_iterator using std::bidirectional_iterator_tag.
[alias] Iterable::BidirectionalIterator
Exposes an iterator using std::bidirectional_iterator_tag.
[alias] Iterable::ForwardConstIterator
Exposes a const_iterator using std::forward_iterator_tag.
[alias] Iterable::ForwardIterator
Exposes an iterator using std::forward_iterator_tag.
[alias] Iterable::InputConstIterator
Exposes a const_iterator using std::input_iterator_tag.
[alias] Iterable::InputIterator
Exposes an iterator using std::input_iterator_tag.
[alias] Iterable::RandomAccessConstIterator
Exposes a const_iterator using std::random_access_iterator_tag.
[alias] Iterable::RandomAccessIterator
Exposes an iterator using std::random_access_iterator_tag.
Member Function Documentation
bool Iterable::containsKey(const QVariant &key) const
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.
QMetaAssociation::Iterable::ConstIterator Iterable::find(const QVariant &key) const
Retrieves a ConstIterator 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 Iterable::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.
QMetaAssociation::Iterable::Iterator Iterable::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 Iterable::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 Iterable::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 Iterable::value(const QVariant &key) const
Retrieves the mapped value at the given key, or a QVariant of a default-constructed instance 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().
© 2025 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.