QMetaSequence::Iterable Class
class QMetaSequence::IterableThe QMetaSequence::Iterable class is an iterable interface for a 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
Detailed Description
This class allows several methods of accessing the values of a container held within a QVariant. An instance of QMetaSequence::Iterable can be extracted from a QVariant if it can be converted to a QVariantList, or if the container it contains is registered using Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE. Most sequential containers found in Qt and some found in the C++ standard library are automatically registered.
QList<int> intList = {7, 11, 42}; QVariant variant = QVariant::fromValue(intList); if (variant.canConvert<QVariantList>()) { QMetaSequence::Iterable iterable = variant.value<QMetaSequence::Iterable>(); // Can use C++11 range-for: for (const QVariant &v : iterable) { qDebug() << v; } // Can use iterators: QMetaSequence::Iterable::const_iterator it = iterable.begin(); const QMetaSequence::Iterable::const_iterator end = iterable.end(); for ( ; it != end; ++it) { qDebug() << *it; } }
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
QVariant Iterable::at(qsizetype idx) const
Returns the value at position idx in the container.
Note: If the underlying container does not provide a native way to retrieve an element at an index, this method will synthesize the access using iterators. This behavior is deprecated and will be removed in a future version of Qt.
See also setAt().
void Iterable::setAt(qsizetype idx, const QVariant &value)
Sets the element at position idx in the container to value.
See also at().
© 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.