QJsonObject::const_iterator Class
class QJsonObject::const_iteratorQJsonObject::const_iterator 类为QJsonObject 提供了STL风格的const迭代器。更多内容...
- 所有成员列表(包括继承的成员)
- const_iterator 是Qt 中 JSON 支持的一部分。
QJsonObject::const_iterator 比较
| 类别 | 可比较类型 |
|---|---|
| strong | QJsonObject::const_iterator |
| strong | QJsonObject::iterator. |
公共类型
公共函数
| const_iterator() | |
| const_iterator(const QJsonObject::iterator &other) | |
| const_iterator(const QJsonObject::const_iterator &other) | |
| QString | key() const |
(since 6.10) QAnyStringView | keyView() const |
| QJsonValueConstRef | value() const |
| const QJsonValueConstRef | operator*() const |
| QJsonObject::const_iterator | operator+(qsizetype j) const |
| QJsonObject::const_iterator & | operator++() |
| QJsonObject::const_iterator | operator++(int) |
| QJsonObject::const_iterator & | operator+=(qsizetype j) |
| qsizetype | operator-(QJsonObject::const_iterator other) const |
| QJsonObject::const_iterator | operator-(qsizetype j) const |
| QJsonObject::const_iterator & | operator--() |
| QJsonObject::const_iterator | operator--(int) |
| QJsonObject::const_iterator & | operator-=(qsizetype j) |
| const QJsonValueConstRef * | operator->() const |
| QJsonValueConstRef | operator[](qsizetype j) const |
相关的非成员
| bool | operator!=(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
| bool | operator<(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
| bool | operator<=(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
| bool | operator==(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
| bool | operator>(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
| bool | operator>=(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs) |
详细说明
QJsonObject::const_iterator 允许您遍历QJsonObject 。如果您希望在遍历过程中修改QJsonObject ,则必须改用QJsonObject::iterator 。通常,对非const类型的QJsonObject 使用QJsonObject::const_iterator 也是良好的编程实践,除非您需要通过迭代器修改QJsonObject 。const迭代器速度稍快,且能提高代码可读性。
默认的QJsonObject::const_iterator 构造函数会创建一个未初始化的迭代器。在开始迭代之前,您必须使用QJsonObject 函数(如QJsonObject::constBegin()、QJsonObject::constEnd() 或QJsonObject::find())对其进行初始化。
同一个对象上可以使用多个迭代器。但是,如果对象被修改,现有的迭代器将变为悬空迭代器。
另请参阅 QJsonObject::iterator 、Qt 中的 JSON 支持,以及游戏的保存与加载。
成员类型文档
const_iterator::iterator_category
std::random_access_iterator_tag的同义词,用于表示该迭代器是随机访问迭代器。
注意:在 Qt 5.6 之前的版本中,该值曾被误设为std::bidirectional_iterator_tag。
成员函数文档
const_iterator::const_iterator()
构建一个未初始化的迭代器。
不得在未初始化的迭代器上调用诸如key()、value() 和 operator++() 之类的函数。使用 operator=() 向其赋值后再使用。
另请参阅 QJsonObject::constBegin() 和QJsonObject::constEnd()。
const_iterator::const_iterator(const QJsonObject::iterator &other)
创建other 的副本。
[constexpr noexcept default] const_iterator::const_iterator(const QJsonObject::const_iterator &other)
复制并构造一个const_iterator 的实例。
QString const_iterator::key() const
返回当前项的键。
[since 6.10] QAnyStringView const_iterator::keyView() const
返回当前项的键,格式为QAnyStringView 。此函数不会分配内存。
由于QJsonObject 以US-ASCII、UTF-8或UTF-16格式存储键,因此返回的QAnyStringView 可能采用上述任意一种编码。
该函数于 Qt 6.10 中引入。
QJsonValueConstRef const_iterator::value() const
返回当前项的值。
另请参阅 key()、keyView() 和operator*()。
const QJsonValueConstRef const_iterator::operator*() const
返回当前项的值。
与value()相同。
QJsonObject::const_iterator const_iterator::operator+(qsizetype j) const
返回一个迭代器,该迭代器指向距离当前迭代器向前j 个位置处的项。如果j 为负数,则迭代器向后移动。
当 `j ` 值较大时,此操作可能会比较慢。
另请参阅 operator-()。
QJsonObject::const_iterator &const_iterator::operator++()
前缀运算符++ (++i )会将迭代器向前移动到对象中的下一个元素,并返回指向新当前元素的迭代器。
在 `QJsonObject::end()` 上调用此函数会导致未定义的结果。
另请参阅 operator--()。
QJsonObject::const_iterator const_iterator::operator++(int)
后缀运算符++ (i++ )将迭代器向前移动到对象中的下一个元素,并返回指向先前当前元素的迭代器。
这是一个重载函数。
QJsonObject::const_iterator &const_iterator::operator+=(qsizetype j)
将迭代器向前移动j 个项目。如果j 为负数,则迭代器向后移动。
当j 的值较大时,此操作可能比较慢。
另请参阅 operator-=() 和operator+()。
qsizetype const_iterator::operator-(QJsonObject::const_iterator other) const
返回从other 所指向的项目到本迭代器所指向的项目之间的项目数量。
QJsonObject::const_iterator const_iterator::operator-(qsizetype j) const
返回一个迭代器,该迭代器指向从当前迭代器向后移动j 个位置处的项。如果j 为负数,则迭代器向前移动。
当 `j ` 值较大时,此操作可能较慢。
另请参阅 operator+()。
QJsonObject::const_iterator &const_iterator::operator--()
前缀-- 运算符(--i )将前一个元素设为当前元素,并返回一个指向新当前元素的迭代器。
在 `QJsonObject::begin()` 上调用此函数将导致未定义的结果。
另请参阅 operator++()。
QJsonObject::const_iterator const_iterator::operator--(int)
后缀运算符-- (i-- )将前一个元素设为当前元素,并返回一个指向先前当前元素的迭代器。
这是一个重载函数。
QJsonObject::const_iterator &const_iterator::operator-=(qsizetype j)
使迭代器向后移动j 个元素。如果j 为负数,则迭代器向前移动。
当j 值较大时,此操作可能会比较慢。
另请参阅 operator+=() 和operator-()。
const QJsonValueConstRef *const_iterator::operator->() const
返回指向当前项的指针。
QJsonValueConstRef const_iterator::operator[](qsizetype j) const
返回从该迭代器所指向的项目(位于位置*this + j 的项目)开始,偏移量为j 处的项目。
提供此函数是为了使QJsonObject 迭代器表现得像 C++ 指针一样。
另请参阅 operator+()。
相关非成员
[noexcept] bool operator!=(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs)
如果lhs 指向的项与rhs 迭代器指向的项不同,则返回true ;否则返回false 。
另请参阅 operator==()。
[noexcept] bool operator<(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs)
如果由 `lhs ` 迭代器指向的项目小于由 `rhs ` 迭代器指向的项目,则返回 `true `。
[noexcept] bool operator<=(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs)
如果由迭代器 `lhs ` 所指向的元素小于或等于由迭代器 `rhs ` 所指向的元素,则返回 `true `。
[noexcept] bool operator==(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs)
如果 `lhs ` 指向与 `rhs ` 迭代器相同的项,则返回 `true `;否则返回 `false`。
另请参阅 operator!=()。
[noexcept] bool operator>(const QJsonObject::const_iterator &lhs, const QJsonObject::const_iterator &rhs)
如果由迭代器 `lhs ` 指向的元素大于由迭代器 `rhs ` 指向的元素,则返回 `true `。
[noexcept] bool operator>=(const QJsonObject::const_iterator &lhs, const QJsonObject::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.