const_iterator Struct

struct QSequentialIterable ::const_iterator

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

该结构在 Qt 5.2 引入。

公共函数

const_iterator (const const_iterator & other )
const_iterator & operator= (const const_iterator & other )
~const_iterator ()
bool operator!= (const const_iterator & other ) const
const QVariant operator* () const
const_iterator operator+ (int j ) const
const_iterator & operator++ ()
const_iterator operator++ ( int )
const_iterator & operator+= (int j )
const_iterator operator- (int j ) const
const_iterator & operator-- ()
const_iterator operator-- ( int )
const_iterator & operator-= (int j )
bool operator== (const const_iterator & other ) const

详细描述

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

另请参阅 QSequentialIterable .

成员函数文档编制

const_iterator:: const_iterator (const const_iterator & other )

创建副本为 other .

const_iterator &const_iterator:: operator= (const const_iterator & other )

赋值 other to this.

const_iterator:: ~const_iterator ()

销毁 QSequentialIterable::const_iterator .

bool const_iterator:: operator!= (const const_iterator & other ) const

返回 true if other 指向与此迭代器不同的项;否则返回 false .

另请参阅 operator== ().

const QVariant const_iterator:: operator* () const

Returns the current item, converted to a QVariant .

const_iterator const_iterator:: operator+ ( int j ) const

Returns an iterator to the item at j positions forward from this iterator.

另请参阅 operator- () 和 operator+= ().

const_iterator &const_iterator:: operator++ ()

The prefix ++ operator ( ++it ) advances the iterator to the next item in the container and returns an iterator to the new current item.

Calling this function on QSequentialIterable::end () leads to undefined results.

另请参阅 operator-- ().

const_iterator const_iterator:: operator++ ( int )

这是重载函数。

The postfix ++ operator ( it++ ) advances the iterator to the next item in the container and returns an iterator to the previously current item.

const_iterator &const_iterator:: operator+= ( int j )

Advances the iterator by j 项。

另请参阅 operator-= () 和 operator+ ().

const_iterator const_iterator:: operator- ( int j ) const

Returns an iterator to the item at j positions backward from this iterator.

If the container in the QVariant does not support bi-directional iteration, calling this function leads to undefined results.

另请参阅 operator+ (), operator-= (),和 canReverseIterate ().

const_iterator &const_iterator:: operator-- ()

The prefix -- operator ( --it ) makes the preceding item current and returns an iterator to the new current item.

Calling this function on QSequentialIterable::begin () leads to undefined results.

If the container in the QVariant does not support bi-directional iteration, calling this function leads to undefined results.

另请参阅 operator++ () 和 canReverseIterate ().

const_iterator const_iterator:: operator-- ( int )

这是重载函数。

The postfix -- operator ( it-- ) makes the preceding item current and returns an iterator to the previously current item.

If the container in the QVariant does not support bi-directional iteration, calling this function leads to undefined results.

另请参阅 canReverseIterate ().

const_iterator &const_iterator:: operator-= ( int j )

Makes the iterator go back by j 项。

If the container in the QVariant does not support bi-directional iteration, calling this function leads to undefined results.

另请参阅 operator+= (), operator- (),和 canReverseIterate ().

bool const_iterator:: operator== (const const_iterator & other ) const

返回 true if other points to the same item as this iterator; otherwise returns false .

另请参阅 operator!= ().