QSequentialIterable Class

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

Header: #include <QSequentialIterable>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Since: Qt 5.2
Inherits: QIterable

Public Types

Public Functions

QSequentialIterable(const T *p)
QSequentialIterable(T *p)
QSequentialIterable()
QSequentialIterable(const QMetaSequence &metaSequence, Pointer iterable)
QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType, void *iterable)
QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType, const void *iterable)
QSequentialIterable(QIterable<QMetaSequence> &&other)
void addValue(const QVariant &value, QSequentialIterable::Position position = Unspecified)
QVariant at(qsizetype idx) const
QSequentialIterable::const_iterator begin() const
QSequentialIterable::const_iterator constBegin() const
QSequentialIterable::const_iterator constEnd() const
QSequentialIterable::const_iterator end() const
QSequentialIterable::iterator mutableBegin()
QSequentialIterable::iterator mutableEnd()
void removeValue(QSequentialIterable::Position position = Unspecified)
void set(qsizetype idx, const QVariant &value)
QMetaType valueMetaType() const
QSequentialIterable &operator=(QIterable<QMetaSequence> &&other)

Detailed Description

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

The container itself is not copied before iterating over it.

See also QVariant.

Member Type Documentation

[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.

enum QSequentialIterable::Position

[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.

Member Function Documentation

template <typename T> QSequentialIterable::QSequentialIterable(const T *p)

Default constructs an instance of QSequentialIterable.

template <typename T> QSequentialIterable::QSequentialIterable(T *p)

Default constructs an instance of QSequentialIterable.

QSequentialIterable::QSequentialIterable()

Default constructs an instance of QSequentialIterable.

template <typename Pointer> QSequentialIterable::QSequentialIterable(const QMetaSequence &metaSequence, Pointer iterable)

Default constructs an instance of QSequentialIterable.

QSequentialIterable::QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType, void *iterable)

Default constructs an instance of QSequentialIterable.

QSequentialIterable::QSequentialIterable(const QMetaSequence &metaSequence, const QMetaType &metaType, const void *iterable)

Default constructs an instance of QSequentialIterable.

QSequentialIterable::QSequentialIterable(QIterable<QMetaSequence> &&other)

Default constructs an instance of QSequentialIterable.

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

Adds value to the container, at position, if possible.

QVariant QSequentialIterable::at(qsizetype idx) const

Returns the value at position idx in the container.

QSequentialIterable::const_iterator QSequentialIterable::begin() const

QSequentialIterable::const_iterator QSequentialIterable::constBegin() const

QSequentialIterable::const_iterator QSequentialIterable::constEnd() const

QSequentialIterable::const_iterator QSequentialIterable::end() const

QSequentialIterable::iterator QSequentialIterable::mutableBegin()

QSequentialIterable::iterator QSequentialIterable::mutableEnd()

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.

QMetaType QSequentialIterable::valueMetaType() const

QSequentialIterable &QSequentialIterable::operator=(QIterable<QMetaSequence> &&other)

Move-assignment operator.

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