QSequentialIterable Class

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

Header: #include <QSequentialIterable>
qmake: QT += core
Since: Qt 5.2

This class was introduced in Qt 5.2.

Public Types

Detailed Description

This class allows several methods of accessing the elements of a container held within a QVariant. An instance of QSequentialIterable can be extracted from a QVariant if it can be converted to a QVariantList.

 QList<int> intList = {7, 11, 42};

 QVariant variant = QVariant::fromValue(intList);
 if (variant.canConvert<QVariantList>()) {
     QSequentialIterable iterable = variant.value<QSequentialIterable>();
     // Can use foreach:
     foreach (const QVariant &v, iterable) {
         qDebug() << v;
     }
     // Can use C++11 range-for:
     for (const QVariant &v : iterable) {
         qDebug() << v;
     }
     // Can use iterators:
     QSequentialIterable::const_iterator it = iterable.begin();
     const QSequentialIterable::const_iterator end = iterable.end();
     for ( ; it != end; ++it) {
         qDebug() << *it;
     }
 }

The container itself is not copied before iterating over it.

See also QVariant.