QSequentialIterable 类

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

头: #include <QSequentialIterable>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
继承: QIterable

公共类型

BidirectionalConstIterator
BidirectionalIterator
ForwardConstIterator
ForwardIterator
InputConstIterator
InputIterator
RandomAccessConstIterator
RandomAccessIterator
const_iterator
iterator

公共函数

void addValue (const QVariant & value , QSequentialIterable::Position position = Unspecified)
QVariant at (qsizetype idx ) const
void removeValue (QSequentialIterable::Position position = Unspecified)
void set (qsizetype idx , const QVariant & value )

详细描述

This class allows several methods of accessing the values 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;
    }
}
					

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

另请参阅 QVariant .

成员类型文档编制

[alias] QSequentialIterable:: BidirectionalConstIterator

Exposes a const_iterator using std::bidirectional_iterator_tag.

[alias] QSequentialIterable:: BidirectionalIterator

Exposes an iterator using std::bidirectional_iterator_tag.

[alias] QSequentialIterable:: ForwardConstIterator

Exposes a const_iterator using std::forward_iterator_tag.

[alias] QSequentialIterable:: ForwardIterator

Exposes an iterator using std::forward_iterator_tag.

[alias] QSequentialIterable:: InputConstIterator

Exposes a const_iterator using std::input_iterator_tag.

[alias] QSequentialIterable:: InputIterator

Exposes an iterator using std::input_iterator_tag.

[alias] QSequentialIterable:: RandomAccessConstIterator

Exposes a const_iterator using std::random_access_iterator_tag.

[alias] QSequentialIterable:: RandomAccessIterator

Exposes an iterator using std::random_access_iterator_tag.

[alias] QSequentialIterable:: const_iterator

The QSequentialIterable::const_iterator allows iteration over a container in a QVariant .

A QSequentialIterable::const_iterator can only be created by a QSequentialIterable instance, and can be used in a way similar to other stl-style iterators.

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;
    }
}
					

[alias, since 6.0] QSequentialIterable:: iterator

The QSequentialIterable::iterator allows iteration over a container in a QVariant .

A QSequentialIterable::iterator can only be created by a QSequentialIterable instance, and can be used in a way similar to other stl-style iterators.

This typedef was introduced in Qt 6.0.

成员函数文档编制

void QSequentialIterable:: addValue (const QVariant & value , QSequentialIterable::Position position = Unspecified)

添加 value to the container, at position , if possible.

QVariant QSequentialIterable:: at ( qsizetype idx ) const

Returns the value at position idx in the container.

void QSequentialIterable:: removeValue ( QSequentialIterable::Position position = Unspecified)

Removes a value from the container, at position , if possible.

void QSequentialIterable:: set ( qsizetype idx , const QVariant & value )

Sets the element at position idx in the container to value .