QJsonArray::iterator Class
class QJsonArray::iteratorQJsonArray::iterator 类为QJsonArray 提供了STL风格的非const迭代器。更多内容...
QJsonArray::iterator 比较
| 类别 | 可比较类型 |
|---|---|
| strong | QJsonArray::iterator |
| strong | QJsonArray::const_iterator. |
公共类型
公共函数
| iterator() | |
| iterator(const QJsonArray::iterator &other) | |
| QJsonValueRef | operator*() const |
| QJsonArray::iterator | operator+(qsizetype j) const |
| QJsonArray::iterator & | operator++() |
| QJsonArray::iterator | operator++(int) |
| QJsonArray::iterator & | operator+=(qsizetype j) |
| qsizetype | operator-(QJsonArray::iterator other) const |
| QJsonArray::iterator | operator-(qsizetype j) const |
| QJsonArray::iterator & | operator--() |
| QJsonArray::iterator | operator--(int) |
| QJsonArray::iterator & | operator-=(qsizetype j) |
| const QJsonValueConstRef * | operator->() const |
| QJsonValueRef | operator[](qsizetype j) const |
相关的非成员
| bool | operator!=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator!=(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
| bool | operator<(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator<(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
| bool | operator<=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator<=(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
| bool | operator==(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator==(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
| bool | operator>(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator>(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
| bool | operator>=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs) |
| bool | operator>=(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs) |
详细说明
QJsonArray::iterator 允许您遍历QJsonArray ,并修改与该迭代器关联的数组项。若需遍历constQJsonArray ,请改用QJsonArray::const_iterator 。通常,对非constQJsonArray 也应使用QJsonArray::const_iterator ,除非您需要通过迭代器修改QJsonArray 。常量迭代器速度稍快,且能提高代码可读性。
默认的QJsonArray::iterator 构造函数会创建一个未初始化的迭代器。在开始迭代之前,必须使用QJsonArray 函数(如QJsonArray::begin()、QJsonArray::end()或QJsonArray::insert())对其进行初始化。
大多数QJsonArray 函数接受整数索引而非迭代器。因此,迭代器在与QJsonArray 配合使用时很少派上用场。STL 风格的迭代器唯一有意义的用法是作为generic algorithms 的参数。
同一个数组上可以使用多个迭代器。但请注意,对QJsonArray 执行任何非const函数调用都会导致所有现有迭代器行为未定义。
另请参阅 QJsonArray::const_iterator 。
成员函数文档
iterator::iterator()
构建一个未初始化的迭代器。
不应在未初始化的迭代器上调用 operator*() 和 operator++() 等函数。使用前请先使用 operator=() 向其赋值。
另请参阅 QJsonArray::begin() 和QJsonArray::end()。
[constexpr noexcept default] iterator::iterator(const QJsonArray::iterator &other)
复制并构造一个iterator 实例。
QJsonValueRef iterator::operator*() const
返回对当前项的可修改引用。
您可以在赋值语句的左侧使用 *() 运算符来更改项目的值。
返回值的类型为QJsonValueRef ,这是QJsonArray 和QJsonObject 的辅助类。当您获得一个QJsonValueRef 类型的对象时,可以将其视为对QJsonValue 的引用。如果您对其进行赋值,则该赋值将应用于您从中获取该引用的QJsonObject 的QJsonArray 中的字符。
QJsonArray::iterator iterator::operator+(qsizetype j) const
返回一个迭代器,该迭代器指向距离当前迭代器向前j 个位置处的项。如果j 为负数,则迭代器向后移动。
另请参阅 operator-() 和operator+=()。
QJsonArray::iterator &iterator::operator++()
前缀运算符++ (++it )将迭代器向前移动到数组中的下一个元素,并返回指向新当前元素的迭代器。
在 `QJsonArray::end()` 上调用此函数将导致未定义的结果。
另请参阅 operator--()。
QJsonArray::iterator iterator::operator++(int)
后缀运算符++ (it++ )将迭代器向前移动到数组中的下一个元素,并返回一个指向先前当前元素的迭代器。
这是一个重载函数。
QJsonArray::iterator &iterator::operator+=(qsizetype j)
将迭代器向前移动j 个项目。如果j 为负数,则迭代器向后移动。
另请参阅 operator-=() 和operator+()。
qsizetype iterator::operator-(QJsonArray::iterator other) const
返回从other 所指向的项到本迭代器所指向的项之间的项的数量。
QJsonArray::iterator iterator::operator-(qsizetype j) const
返回一个迭代器,该迭代器指向从当前迭代器向后j 位置处的项目。如果j 为负数,则迭代器向前移动。
另请参阅 operator+() 和operator-=()。
QJsonArray::iterator &iterator::operator--()
前缀运算符-- (--it )将前一个元素设为当前元素,并返回指向新当前元素的迭代器。
在 `QJsonArray::begin()` 上调用此函数将导致未定义的结果。
另请参见 operator++()。
QJsonArray::iterator iterator::operator--(int)
后缀运算符-- (it-- )将前一个项设为当前项,并返回指向先前当前项的迭代器。
这是一个重载函数。
QJsonArray::iterator &iterator::operator-=(qsizetype j)
使迭代器向后移动j 个元素。如果j 为负数,则迭代器向前移动。
另请参阅 operator+=() 和operator-()。
const QJsonValueConstRef *iterator::operator->() const
返回一个指向当前项目可修改引用指针。
QJsonValueRef iterator::operator[](qsizetype j) const
返回一个可修改的引用,该引用指向由该迭代器所指向的项目(位于位置*this + j 的项目)中偏移量为j 的项目。
提供此函数是为了使QJsonArray 迭代器像 C++ 指针一样工作。
返回值的类型为QJsonValueRef ,这是QJsonArray 和QJsonObject 的辅助类。当您获得一个QJsonValueRef 类型的对象时,可以将其视为对QJsonValue 的引用。如果对其进行赋值,该赋值将作用于您从中获取该引用的QJsonArray 或QJsonObject 中的元素。
另请参阅 operator+()。
相关的非成员
[noexcept] bool operator!=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator!=(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs)
如果lhs 指向的项与rhs 迭代器指向的项不同,则返回true ;否则返回false 。
另请参阅 operator==()。
[noexcept] bool operator<(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator<(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs)
如果由迭代器 `lhs ` 指向的项小于由迭代器 `rhs ` 指向的项,则返回 `true `。
[noexcept] bool operator<=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator<=(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs)
如果由迭代器 `lhs ` 指向的项小于或等于由迭代器 `rhs ` 指向的项,则返回 `true `。
[noexcept] bool operator==(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator==(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs)
如果 `lhs ` 指向与迭代器 `rhs ` 相同的项,则返回 `true `;否则返回 `false`。
另请参阅 operator!=()。
[noexcept] bool operator>(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator>(const QJsonArray::iterator &lhs, const QJsonArray::iterator &rhs)
如果由迭代器 `lhs ` 指向的项大于由迭代器 `rhs ` 指向的项,则返回 `true `。
[noexcept] bool operator>=(const QJsonArray::iterator &lhs, const QJsonArray::const_iterator &rhs)
[noexcept] bool operator>=(const QJsonArray::iterator &lhs, const QJsonArray::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.