QMetaSequence::Iterable Class | Qt Core | Qt 6.11.0
Description: The QMetaSequence::Iterable class is an iterable interface for a container in a QVariant.

- Qt 6.11
- Qt Core
- C++ Classes
- Iterable
- Qt 6.11.0 Reference Documentation

# QMetaSequence::Iterable Class

class QMetaSequence::Iterable

The QMetaSequence::Iterable class is an iterable interface for a container in a QVariant. More...

This class was introduced in Qt 6.11.

- List of all members, including inherited members

## Public Types

`(since 6.11)` class | ConstIterator
`(since 6.11)` class | Iterator
| BidirectionalConstIterator
| BidirectionalIterator
| ForwardConstIterator
| ForwardIterator
| InputConstIterator
| InputIterator
| RandomAccessConstIterator
| RandomAccessIterator

## Public Functions

QVariant | at(qsizetype idx) const
void | setAt(qsizetype idx, const QVariant &value)

## 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().