QSequentialIterable 类

QSequentialIterable 类是用于容器的可迭代接口,在 QVariant . 更多...

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

该类在 Qt 5.2 引入。

公共类型

struct const_iterator

公共函数

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

详细描述

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 若它可以被转换成 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;
    }
}
					

容器本身不会被拷贝,在遍历它之前。

另请参阅 QVariant .

成员函数文档编制

QVariant QSequentialIterable:: at ( int idx ) const

Returns the element at position idx in the container.

QSequentialIterable::const_iterator QSequentialIterable:: begin () const

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

另请参阅 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.

QSequentialIterable::const_iterator QSequentialIterable:: end () const

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

另请参阅 begin ().

int QSequentialIterable:: size () const

Returns the number of elements in the container.