このページでは

QJsonObject::iterator Class

class QJsonObject::iterator

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

QJsonObject::iterator の比較

カテゴリ比較可能な型
strongQJsonObject::iterator
strongQJsonObject::const_iterator.

パブリック型

パブリック関数

iterator()
iterator(const QJsonObject::iterator &other)
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 を変更する必要がない限り、非 const のQJsonObject に対してもQJsonObject::const_iterator を使用するのが一般的なベストプラクティスです。const イテレータは若干高速であり、コードの可読性を向上させます。

デフォルトのQJsonObject::iterator コンストラクタは、初期化されていないイテレータを作成します。反復処理を開始する前に、QJsonObject::begin()、QJsonObject::end()、またはQJsonObject::find() といったQJsonObject 関数を使用して、イテレータを初期化する必要があります。

同じオブジェクトに対して複数のイテレータを使用することができます。ただし、オブジェクトが変更されると、既存のイテレータはダングリングイテレータとなってしまいます。

「 QJsonObject::const_iterator」 、「Qt XML における 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()も参照してください 。

[constexpr noexcept default] iterator::iterator(const QJsonObject::iterator &other)

iterator のインスタンスをコピーして生成します。

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() を使用することで、項の値を変更できます。

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

key()、keyView()、およびoperator*()も参照してください 。

QJsonValueRef iterator::operator*() const

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

value() と同じです。

戻り値の型はQJsonValueRef です。これは、QJsonArray およびQJsonObject のヘルパークラスです。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++ のポインタのように振る舞うようにするために提供されています。

戻り値の型はQJsonValueRef であり、これはQJsonArray およびQJsonObject のヘルパークラスです。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 を返します。

[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 を返し、そうでない場合は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 を返します。

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