From afbc2c75e32213db15f5a18ba5fe38822af49882 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 10 Jun 2014 10:41:28 +0200 Subject: json: Add defaultValue to QJsonValueRef toInt/toBool/toDouble/toString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently QJsonValue and QJsonValueRef behave differently in regard to the default values leading to confusion compile errors depending on which of the two types one is actually using. Before this change it was possible to write: QJsonValue value = jsonObject["item"]; QString name = value.toString(QStringLiteral("default")); but not: QString name = jsonObject["item"].toString(QStringLiteral("default")); Change-Id: Id1185acf339aa3a91e97848e85d068f84552df71 Reviewed-by: Lars Knoll Reviewed-by: Jędrzej Nowacki --- src/corelib/json/qjsonvalue.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/json') diff --git a/src/corelib/json/qjsonvalue.h b/src/corelib/json/qjsonvalue.h index fe028990c0..97e20b574d 100644 --- a/src/corelib/json/qjsonvalue.h +++ b/src/corelib/json/qjsonvalue.h @@ -170,6 +170,12 @@ public: QJsonArray toArray() const; QJsonObject toObject() const; + // ### Qt 6: Add default values + inline bool toBool(bool defaultValue) const { return toValue().toBool(defaultValue); } + inline int toInt(int defaultValue) const { return toValue().toInt(defaultValue); } + inline double toDouble(double defaultValue) const { return toValue().toDouble(defaultValue); } + inline QString toString(const QString &defaultValue) const { return toValue().toString(defaultValue); } + inline bool operator==(const QJsonValue &other) const { return toValue() == other; } inline bool operator!=(const QJsonValue &other) const { return toValue() != other; } -- cgit v1.2.3