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

Public Types

Public Functions

QVariant at(int idx) const
const_iterator begin() const
bool canReverseIterate() const
const_iterator end() const
int size() const

Detailed Description

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

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;
intList.push_back(7);
intList.push_back(11);
intList.push_back(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.

Member Function Documentation

QVariant QSequentialIterable::​at(int idx) const

Returns the element at position idx in the container.

const_iterator QSequentialIterable::​begin() const

Returns a QSequentialIterable::const_iterator for the beginning of the container. This can be used in stl-style iteration.

See also end().

bool QSequentialIterable::​canReverseIterate() const

Returns whether it is possible to iterate over the container in reverse. This corresponds to the std::bidirectional_iterator_tag iterator trait of the const_iterator of the container.

const_iterator QSequentialIterable::​end() const

Returns a QSequentialIterable::const_iterator for the end of the container. This can be used in stl-style iteration.

See also begin().

int QSequentialIterable::​size() const

Returns the number of elements in the container.

© 2015 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.