本页内容

QCborArray::Iterator Class

class QCborArray::Iterator

QCborArray::Iterator 类为QCborArray 提供了一个STL风格的非const迭代器。更多内容...

QCborArray::Iterator 比较

类别可比较的类型
strongQCborArray::Iterator
strongQCborArray::ConstIterator.

公共类型

公共函数

Iterator()
Iterator(const QCborArray::Iterator &other)
QCborValueRef operator*() const
QCborArray::Iterator operator+(qsizetype j) const
QCborArray::Iterator &operator++()
QCborArray::Iterator operator++(int)
QCborArray::Iterator &operator+=(qsizetype j)
qsizetype operator-(QCborArray::Iterator other) const
QCborArray::Iterator operator-(qsizetype j) const
QCborArray::Iterator &operator--()
QCborArray::Iterator operator--(int)
QCborArray::Iterator &operator-=(qsizetype j)
const QCborValueConstRef *operator->() const
QCborArray::Iterator &operator=(const QCborArray::Iterator &other)
QCborValueRef operator[](qsizetype j) const
bool operator!=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator!=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)
bool operator<(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator<(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)
bool operator<=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator<=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)
bool operator==(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator==(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)
bool operator>(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator>(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)
bool operator>=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)
bool operator>=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

详细说明

QCborArray::Iterator 允许您遍历一个QCborArray ,并修改与该迭代器关联的数组项。如果您需要遍历一个constQCborArray ,请改用QCborArray::ConstIterator 。通常,对于非constQCborArray ,也建议使用QCborArray::ConstIterator ,除非您需要通过迭代器修改QCborArray 。const迭代器速度稍快,且能提高代码可读性。

迭代器需通过QCborArray 函数(如QCborArray::begin()、QCborArray::end() 或QCborArray::insert())进行初始化。只有完成初始化后,才能进行迭代操作。

大多数QCborArray 函数接受整数索引而非迭代器。因此,迭代器在与QCborArray 配合使用时很少派上用场。STL 风格迭代器真正有意义的场景之一是作为generic algorithms 的参数。

同一个数组上可以使用多个迭代器。但请注意,对QCborArray 执行任何非const函数调用都会导致所有现有迭代器行为未定义。

另请参阅 QCborArray::ConstIterator 。

成员类型文档

Iterator::iterator_category

std::random_access_iterator_tag的同义词,表示该迭代器是随机访问迭代器。

成员函数文档

[constexpr noexcept default] Iterator::Iterator()

构建一个未初始化的迭代器。

不应在未初始化的迭代器上调用 operator*() 和 operator++() 等函数。使用前请先通过 operator=() 向其赋值。

另请参阅 QCborArray::begin() 和QCborArray::end()。

[constexpr noexcept default] Iterator::Iterator(const QCborArray::Iterator &other)

创建other 的副本。

QCborValueRef Iterator::operator*() const

返回指向当前项的可修改引用。

您可以通过在赋值语句的左侧使用 operator*() 来更改项的值。

返回值的类型为 QCborValueRef,这是QCborArray 和QCborMap 的辅助类。当您获得一个 QCborValueRef 类型的对象时,可以将其视为对QCborValue 的引用。如果您对其进行赋值,该赋值将应用于您从中获取该引用的QCborArray 或QCborMap 中的元素。

QCborArray::Iterator Iterator::operator+(qsizetype j) const

返回一个迭代器,该迭代器指向从当前迭代器向前移动j 步处的项目。如果j 为负数,则迭代器向后移动。

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

QCborArray::Iterator &Iterator::operator++()

前缀++ 运算符(++it )将迭代器向前移动到数组中的下一个元素,并返回该迭代器。

在 `QCborArray::end()` 上调用此函数会导致未定义的结果。

另请参阅 operator--()。

QCborArray::Iterator Iterator::operator++(int)

后缀运算符++ (it++ )将迭代器向前移动到数组中的下一个元素,并返回指向前一个当前元素的迭代器。

这是一个重载函数。

QCborArray::Iterator &Iterator::operator+=(qsizetype j)

将迭代器向前移动j 个位置。如果j 为负数,则迭代器向后移动。返回对此迭代器的引用。

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

qsizetype Iterator::operator-(QCborArray::Iterator other) const

返回该迭代器相对于other 的偏移量。

QCborArray::Iterator Iterator::operator-(qsizetype j) const

返回一个迭代器,该迭代器指向从当前迭代器向后移动j 个步长处的位置。如果j 为负数,则迭代器向前移动。

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

QCborArray::Iterator &Iterator::operator--()

前缀-- 运算符(--it )将前一个元素设为当前元素,并返回该迭代器。

在 `QCborArray::begin()` 上调用此函数将导致未定义的结果。

另请参阅 operator++()。

QCborArray::Iterator Iterator::operator--(int)

后缀运算符-- (it-- )将前一个元素设为当前元素,并返回指向先前当前元素的迭代器。

这是一个重载函数。

QCborArray::Iterator &Iterator::operator-=(qsizetype j)

使迭代器向后移动j 个位置。如果j 为负数,则迭代器向前移动。返回对该迭代器的引用。

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

const QCborValueConstRef *Iterator::operator->() const

返回指向当前项的可修改引用指针。

QCborArray::Iterator &Iterator::operator=(const QCborArray::Iterator &other)

将该迭代器设为other 的副本,并返回对该迭代器的引用。

QCborValueRef Iterator::operator[](qsizetype j) const

返回一个可修改的引用,该引用指向从本迭代器所指向的项目向前移动j 步处的位置。

提供此函数是为了使QCborArray 迭代器像 C++ 指针一样工作。

返回值的类型为 QCborValueRef,这是QCborArray 和QCborMap 的辅助类。当您获得一个 QCborValueRef 类型的对象时,可以将其视为对QCborValue 的引用。如果您对其进行赋值,该赋值将应用于您从中获取该引用的QCborArray 或QCborMap 中的元素。

另请参阅 operator+()。

相关的非成员

[noexcept] bool operator!=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator!=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果 `lhs ` 指向数组中与迭代器 `rhs ` 不同的条目,则返回 `true `;否则返回 `false`。

另请参阅 operator==()。

[noexcept] bool operator<(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator<(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果由迭代器 `lhs ` 指向的数组项出现在由迭代器 `rhs ` 指向的项之前,则返回 `true `。

[noexcept] bool operator<=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator<=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果由迭代器 `lhs ` 指向的数组中的条目出现在迭代器 `rhs ` 指向的条目之前,或者与该条目相同,则返回 `true `。

[noexcept] bool operator==(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator==(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果lhs 指向与迭代器rhs 相同的数组项,则返回true ;否则返回false 。

另请参阅 operator!=()。

[noexcept] bool operator>(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator>(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果由迭代器 `lhs ` 指向的数组中的条目位于由迭代器 `rhs ` 指向的条目之后,则返回 `true `。

[noexcept] bool operator>=(const QCborArray::Iterator &lhs, const QCborArray::ConstIterator &rhs)

[noexcept] bool operator>=(const QCborArray::Iterator &lhs, const QCborArray::Iterator &rhs)

如果由迭代器 `lhs ` 指向的数组中的条目位于迭代器 `rhs ` 所指向的条目之后,或者与该条目相同,则返回 `true `。

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