QJsonObject::iterator Class

class QJsonObject::iterator

QJsonObject::iterator クラスは、QJsonObject 用の STL スタイルの非 const イテレータを提供します。詳細...

このクラスは強く比較可能です。

このクラスはQJsonObject::const_iterator強く比較可能です。

パブリック型

パブリック関数

iterator()
QString key() const
(since 6.10) QAnyStringView keyView() const
QJsonValueRef value() const
QJsonValueRef operator*() const
QJsonObject::iterator operator+(qsizetype j) const
QJsonObject::iterator &operator++()
QJsonObject::iterator operator++(int)
QJsonObject::iterator &operator+=(qsizetype j)
qsizetype operator-(QJsonObject::iterator other) const
QJsonObject::iterator operator-(qsizetype j) const
QJsonObject::iterator &operator--()
QJsonObject::iterator operator--(int)
QJsonObject::iterator &operator-=(qsizetype j)
QJsonValueRef *operator->()
const QJsonValueConstRef *operator->() const
QJsonValueRef operator[](qsizetype j) const
bool operator!=(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator!=(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)
bool operator<(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator<(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)
bool operator<=(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator<=(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)
bool operator==(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator==(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)
bool operator>(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator>(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)
bool operator>=(const QJsonObject::iterator &lhs, const QJsonObject::const_iterator &rhs)
bool operator>=(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)

詳細説明

QJsonObject::iterator を使用すると、QJsonObject を繰り返し処理したり、特定のキーの下に格納されている値 (キーではなく) を変更したりすることができます。constQJsonObject を繰り返し処理する場合は、QJsonObject::const_iterator を使用する必要があります。イテレータを使用してQJsonObject を変更する必要がない限り、constQJsonObject 以外にQJsonObject::const_iterator を使用するのが一般的です。const イテレータのほうが若干高速で、コードの可読性も向上します。

デフォルトのQJsonObject::iterator コンストラクタは、初期化されていないイテレータを作成します。QJsonObject::begin ()、QJsonObject::end ()、QJsonObject::find ()のようなQJsonObject 関数を使用して初期化しなければなりません。

同じオブジェクトに複数のイテレータを使用することができます。ただし、オブジェクトが変更されると、既存のイテレータはぶら下がった状態になります。

QJsonObject::const_iteratorQtのJSONサポートゲームの保存と読み込みも参照してください

メンバ型のドキュメント

iterator::iterator_category

std::random_access_iterator_tagの同義語で、このイテレータがランダムアクセスイテレータであることを示します。

注意: Qt 5.6 より前のバージョンでは、誤ってstd::bidirectional_iterator_tag に設定されていました。

メンバ関数ドキュメント

iterator::iterator()

初期化されていないイテレータを構築します。

key()、value()、 operator++() などの関数を、初期化されていないイテレータで呼び出してはいけません。operator=() を使用して値を代入してから使用してください。

QJsonObject::begin() およびQJsonObject::end()も参照してください

QString iterator::key() const

現在のアイテムのキーを返します。

アイテムのキーをイテレータで直接変更する方法はありませんが、QJsonObject::erase() の後にQJsonObject::insert() を呼び出すことで可能です。

value() およびkeyView()も参照

[since 6.10] QAnyStringView iterator::keyView() const

QAnyStringViewこの関数はメモリを割り当てない。

QJsonObject はキーを US-ASCII、UTF-8、または UTF-16 で格納するので、返されるQAnyStringView はこれらのエンコーディングのいずれでもかまいません。

イテレータを通してアイテムのキーを変更する直接的な方法はありませんが、QJsonObject::erase() の後にQJsonObject::insert() を呼び出すことで可能です。

この関数は Qt 6.10 で導入されました。

key() およびvalue()も参照して ください。

QJsonValueRef iterator::value() const

現在の項目の値への変更可能な参照を返します。

項目の値を変更するには、代入の左辺で value() を使用します。

戻り値は、QJsonArray およびQJsonObject のヘルパー・クラスであるQJsonValueRef 型です。QJsonValueRef 型のオブジェクトを取得すると、それをQJsonValue への参照であるかのように使用できます。これに代入すると、その代入は、参照を取得したQJsonArray またはQJsonObject の要素に適用されます。

key()、keyView()、operator*()も参照

QJsonValueRef iterator::operator*() const

現在の項目の値への変更可能な参照を返します。

value() と同じ。

戻り値は、QJsonArray およびQJsonObject のヘルパー・クラスであるQJsonValueRef 型です。QJsonValueRef 型のオブジェクトを取得すると、それをQJsonValue への参照であるかのように使用できます。これに代入すると、その代入は、参照を取得したQJsonArray またはQJsonObject の要素に適用されます。

key() およびkeyView()も参照

QJsonObject::iterator iterator::operator+(qsizetype j) const

このイテレータからj 前方の位置のアイテムへのイテレータを返します。j が負の場合、イテレータは後方に進みます。

operator-()も参照

QJsonObject::iterator &iterator::operator++()

++i前置演算子++ は、イテレータをオブジェクトの次の項目に進め、新しい現在の項目へのイテレータを返す。

この関数をQJsonObject::end() で呼び出すと、未定義の結果になります。

operator--()も参照してください

QJsonObject::iterator iterator::operator++(int)

ポストフィックス++ 演算子、i++ は、イテレータをオブジェクトの次の項目に進め、それ以前の現在の項目へのイテレータを返します。

これはオーバーロードされた関数です。

QJsonObject::iterator &iterator::operator+=(qsizetype j)

イテレータをj アイテム分進めます。j が負の場合、イテレータは後退する。

operator-=() およびoperator+()も参照のこと

qsizetype iterator::operator-(QJsonObject::iterator other) const

other が指すアイテムとこのイテレータが指すアイテムの間のアイテム数を返します。

QJsonObject::iterator iterator::operator-(qsizetype j) const

このイテレータからj 後方の位置のアイテムへのイテレータを返します。j が負の場合、イテレータは前方に進みます。

operator+()も参照

QJsonObject::iterator &iterator::operator--()

接頭辞-- 演算子--i は、直前の項目をカレントにし、新しいカレント項目を指すイテレータを返す。

この関数をQJsonObject::begin() で呼び出すと、未定義の結果になります。

operator++()も参照

QJsonObject::iterator iterator::operator--(int)

ポストフィックス-- 演算子、i-- は、直前の項目をカレントとし、直前のカレント項目を指すイテレータを返します。

これはオーバーロードされた関数です。

QJsonObject::iterator &iterator::operator-=(qsizetype j)

イテレータをj アイテム分戻します。j が負の場合、イテレータは前に進みます。

operator+=() およびoperator-()も参照

QJsonValueRef *iterator::operator->()

現在のアイテムへの変更可能な参照へのポインタを返します。

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

現在のアイテムへの定数参照へのポインタを返します。

QJsonValueRef iterator::operator[](qsizetype j) const

このイテレータが指すアイテム(位置*this + j のアイテム)からオフセットj にあるアイテムへの変更可能な参照を返します。

この関数は、QJsonObject イテレータを C++ ポインタのように動作させるために用意されています。

戻り値は、QJsonArray およびQJsonObject のヘルパー・クラスであるQJsonValueRef 型です。QJsonValueRef 型のオブジェクトを取得すると、それをQJsonValue への参照であるかのように使用できます。これに代入すると、その代入は、参照を取得したQJsonArray またはQJsonObject の要素に適用されます。

operator+()も参照してください

関連する非メンバー

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

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

lhs がイテレータrhs と同じアイテムを指している場合はtrue を返し、そうでない場合はfalse を返す。

operator!=()も参照

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

[noexcept] bool operator!=(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)

lhs がイテレータrhs と異なるアイテムを指している場合はtrue を返し、そうでない場合はfalse を返す。

operator==()も参照

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

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

lhs イテレータが指すアイテムが、rhs イテレータが指すアイテムより小さい場合、true を返す。

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

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

lhs イテレータが指すアイテムが、rhs イテレータが指すアイテム以下である場合、true を返す。

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

[noexcept] bool operator>(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)

lhs イテレータが指すアイテムが、rhs イテレータが指すアイテムより大きい場合、true を返す。

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

[noexcept] bool operator>=(const QJsonObject::iterator &lhs, const QJsonObject::iterator &rhs)

lhs イテレータが指すアイテムが、rhs イテレータが指すアイテム以上であれば、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.