diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2018-06-28 15:09:23 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2018-08-27 13:06:19 +0000 |
| commit | 231273b130d4cc213158ce858262b7f1b7b6fcdd (patch) | |
| tree | ec650d5879a488bfea0860938ac27a083e5436e3 /src/corelib/serialization/qjsonobject.cpp | |
| parent | 112c0632d944114ba2b4eb4875c4f65cd0c261eb (diff) | |
JSON: Add qHash functions for JSON and CBOR types
This way we can easily use them as keys in QHash and QSet.
Change-Id: Ie744c3b5ad1176ba2ab035c7e650af483757a0c9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
| -rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 4a316c8a6f5..950bec535be 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -1292,6 +1292,17 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val) insert(e->key(), val); } +uint qHash(const QJsonObject &object, uint seed) +{ + QtPrivate::QHashCombine hash; + for (auto it = object.begin(), end = object.end(); it != end; ++it) { + const QString key = it.key(); + const QJsonValue value = it.value(); + seed = hash(seed, std::pair<const QString&, const QJsonValue&>(key, value)); + } + return seed; +} + #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) QDebug operator<<(QDebug dbg, const QJsonObject &o) { |
