diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2013-08-22 16:25:13 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-27 08:01:29 +0200 |
commit | 507f1889e2b21d0b3367715dc5e63e124433a992 (patch) | |
tree | 11a077cb1988e05ac94f42b2bb4cd7e476997891 /src/corelib/json/qjsonvalue.cpp | |
parent | f73518e7325faf1359b7f52333aa7c11ed393c8c (diff) |
Add QJsonValue::toInt().
It's a nice feature to have.
MSVC also complains about using doubles to create enum values, so
the ugly workaround is:
enumValue = MyEnum(qRound(json["myEnumValue"].toDouble()));
[ChangeLog][QtCore][QJsonValue]Added QJsonValue::toInt().
Change-Id: I1a200b912abf66b2e96390b1980caff26cfa2685
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/corelib/json/qjsonvalue.cpp')
-rw-r--r-- | src/corelib/json/qjsonvalue.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index 3aba6124b8..ef9f057d77 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -449,6 +449,19 @@ bool QJsonValue::toBool(bool defaultValue) const } /*! + Converts the value to an int and returns it. + + If type() is not Double or the value is not a whole number, + the \a defaultValue will be returned. + */ +int QJsonValue::toInt(int defaultValue) const +{ + if (t == Double && int(dbl) == dbl) + return dbl; + return defaultValue; +} + +/*! Converts the value to a double and returns it. If type() is not Double, the \a defaultValue will be returned. |