QJsonObject::const_iterator Class

class QJsonObject::const_iterator

QJsonObject::const_iterator 类为QJsonObject 提供了 STL 风格的常量迭代器。更多

该类具有很强的可比性

该类与QJsonObject::iterator 具有很强的可比性

公共类型

公共函数

const_iterator()
const_iterator(const QJsonObject::iterator &other)
QString key() 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 允许您遍历 。如果您想在遍历过程中修改 ,则必须使用 。一般来说,除非需要通过迭代器修改 ,否则在非 Const 上使用 也是不错的做法。常量迭代器速度稍快,代码可读性也更好。QJsonObject QJsonObject QJsonObject::iterator QJsonObject QJsonObject QJsonObject::const_iterator

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

可以在同一对象上使用多个迭代器。不过,如果对象被修改,现有的迭代器就会变成悬空的。

另请参阅 QJsonObject::iteratorQt 中的 JSON 支持以及保存和加载游戏

成员类型文档

const_iterator::iterator_category

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

注意: 在 5.6 之前的 Qt 版本中,该标记被错误地设置为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 的副本。

QString const_iterator::key() const

返回当前项目的密钥。

另请参阅 value()。

QJsonValueConstRef const_iterator::value() const

返回当前项目的值。

另请参阅 key() 和operator*()。

const QJsonValueConstRef const_iterator::operator*() const

返回当前项目的值。

value() 相同。

另请参阅 key()。

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 iterator 指向的项目小于rhs iterator 指向的项目,则返回true

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

如果lhs iterator 指向的项目小于或等于rhs iterator 指向的项目,则返回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 iterator 指向的项目大于或等于rhs iterator 指向的项目,则返回true

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