Fixed QJsonObject::find()

The function returns mutable iterator on the object that can later be passed to
e.g. erase(), hence it should detach() to be consistent with
QJsonObject::begin() which also detaches.

Change-Id: Id79e8e012fd5469e06b68fbc9eecb7c6848ce9c1
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
This commit is contained in:
Denis Dzyubenko 2012-06-04 18:52:36 +02:00 committed by Qt by Nokia
parent 9b0aa9dc4c
commit 944221001c
2 changed files with 11 additions and 0 deletions

View File

@ -452,6 +452,7 @@ QJsonObject::iterator QJsonObject::find(const QString &key)
int index = o ? o->indexOf(key, &keyExists) : 0;
if (!keyExists)
return end();
detach();
return iterator(this, index);
}

View File

@ -589,6 +589,16 @@ void TestQtJson::testObjectIteration()
}
}
{
QJsonObject object2 = object;
QVERIFY(object == object2);
QJsonObject::iterator it = object2.find(QString::number(5));
object2.erase(it);
QCOMPARE(object.size(), 10);
QCOMPARE(object2.size(), 9);
}
{
QJsonObject::Iterator it = object.begin();
it += 5;