diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-16 17:44:46 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-17 07:35:49 +0000 |
commit | ab680380196bc5558d519d6bb699014184ee1c56 (patch) | |
tree | f644d6119a7d5994ef0e2c95c0272c1d94e8666c | |
parent | 6a1393148c795a4012c96c43df1262e5ecb8e744 (diff) |
Fix string -> variant conversion in settings model
When storing the settings in the config-ui tool, the JS value undefined
would erroneously get converted to the string "undefined".
Change-Id: I1579a653bc3162afcdcce52983613ebd01b4c23a
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r-- | src/lib/corelib/tools/settingsmodel.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/corelib/tools/settingsmodel.cpp b/src/lib/corelib/tools/settingsmodel.cpp index ba0713a05..a96a98ab8 100644 --- a/src/lib/corelib/tools/settingsmodel.cpp +++ b/src/lib/corelib/tools/settingsmodel.cpp @@ -397,21 +397,21 @@ QString settingsValueToRepresentation(const QVariant &value) return toJSLiteral(value); } -static QVariant variantFromString(const QString &str) +static QVariant variantFromString(const QString &str, bool &ok) { // ### use Qt5's JSON reader at some point. QScriptEngine engine; QScriptValue sv = engine.evaluate(QLatin1String("(function(){return ") + str + QLatin1String(";})()")); - if (sv.isError()) - return QVariant(); + ok = !sv.isError(); return sv.toVariant(); } QVariant representationToSettingsValue(const QString &representation) { - const QVariant variant = variantFromString(representation); - if (variant.isValid()) + bool ok; + const QVariant variant = variantFromString(representation, ok); + if (ok) return variant; // If it's not valid JavaScript, interpret the value as a string. |