本页内容

QJsonArray::const_iterator Class

class QJsonArray::const_iterator

QJsonArray::const_iterator 类为QJsonArray 提供了STL风格的const迭代器。更多内容...

QJsonArray::const_iterator 比较

类别可比较类型
strongQJsonArray::const_iterator
strongQJsonArray::iterator.

公共类型

公共函数

const_iterator()
const_iterator(const QJsonArray::iterator &other)
const_iterator(const QJsonArray::const_iterator &other)
const QJsonValueConstRef operator*() const
QJsonArray::const_iterator operator+(qsizetype j) const
QJsonArray::const_iterator &operator++()
QJsonArray::const_iterator operator++(int)
QJsonArray::const_iterator &operator+=(qsizetype j)
qsizetype operator-(QJsonArray::const_iterator other) const
QJsonArray::const_iterator operator-(qsizetype j) const
QJsonArray::const_iterator &operator--()
QJsonArray::const_iterator operator--(int)
QJsonArray::const_iterator &operator-=(qsizetype j)
const QJsonValueConstRef *operator->() const
QJsonValueConstRef operator[](qsizetype j) const
bool operator!=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator<(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator<=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator==(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator>(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)
bool operator>=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

详细说明

QJsonArray::const_iterator 允许您遍历QJsonArray 。如果您希望在遍历过程中修改QJsonArray ,请改用QJsonArray::iterator 。通常,对非const的QJsonArray 使用QJsonArray::const_iterator 也是一个良好的编程习惯,除非您需要通过迭代器更改QJsonArray 。const迭代器速度稍快,且能提高代码可读性。

默认的QJsonArray::const_iterator 构造函数会创建一个未初始化的迭代器。在开始迭代之前,必须使用QJsonArray 函数(如QJsonArray::constBegin()、QJsonArray::constEnd()或QJsonArray::insert())对其进行初始化。

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

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

另请参阅 QJsonArray::iterator 。

成员类型文档

const_iterator::iterator_category

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

成员函数文档

const_iterator::const_iterator()

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

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

另请参阅 QJsonArray::constBegin() 和QJsonArray::constEnd()。

const_iterator::const_iterator(const QJsonArray::iterator &other)

创建other 的副本。

[constexpr noexcept default] const_iterator::const_iterator(const QJsonArray::const_iterator &other)

复制并构造一个const_iterator 实例。

const QJsonValueConstRef const_iterator::operator*() const

返回当前项。

QJsonArray::const_iterator const_iterator::operator+(qsizetype j) const

返回一个迭代器,该迭代器指向距离本迭代器向前j 个位置处的项。如果j 为负数,则迭代器向后移动。

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

QJsonArray::const_iterator &const_iterator::operator++()

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

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

另请参阅 operator--()。

QJsonArray::const_iterator const_iterator::operator++(int)

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

这是一个重载函数。

QJsonArray::const_iterator &const_iterator::operator+=(qsizetype j)

将迭代器向前移动j 个项。如果j 为负数,则迭代器向后移动。

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

qsizetype const_iterator::operator-(QJsonArray::const_iterator other) const

返回从other 所指向的项目到本迭代器所指向的项目之间的项目数量。

QJsonArray::const_iterator const_iterator::operator-(qsizetype j) const

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

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

QJsonArray::const_iterator &const_iterator::operator--()

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

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

另请参阅 operator++()。

QJsonArray::const_iterator const_iterator::operator--(int)

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

这是一个重载函数。

QJsonArray::const_iterator &const_iterator::operator-=(qsizetype j)

使迭代器向后移动j 个元素。如果j 为负数,则迭代器向前移动。

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

const QJsonValueConstRef *const_iterator::operator->() const

返回指向当前项的指针。

QJsonValueConstRef const_iterator::operator[](qsizetype j) const

返回从该迭代器所指向的项(位于位置*this + j 的项)开始,偏移量为j 的项。

提供此函数是为了使QJsonArray 迭代器表现得像 C++ 指针一样。

另请参阅 operator+()。

相关非成员

[noexcept] bool operator!=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

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

另请参阅 operator==()。

[noexcept] bool operator<(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果由迭代器 `lhs ` 指向的项小于由迭代器 `rhs ` 指向的项,则返回 `true `。

[noexcept] bool operator<=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果由迭代器 `lhs ` 指向的项小于或等于由迭代器 `rhs ` 指向的项,则返回 `true `。

[noexcept] bool operator==(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

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

另请参阅 operator!=()。

[noexcept] bool operator>(const QJsonArray::const_iterator &lhs, const QJsonArray::const_iterator &rhs)

如果由迭代器 `lhs ` 指向的项大于由迭代器 `rhs ` 指向的项,则返回 `true `。

[noexcept] bool operator>=(const QJsonArray::const_iterator &lhs, const QJsonArray::const_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.