aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-05-11 17:19:14 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2017-05-19 08:44:15 +0000
commit5f49b2b3bb30678a26341e1f45e0cfd6a6fd2c57 (patch)
tree401948a4e6ba81d01860da5f2e57150412e72128 /src
parent6a02fb09af8dce6ca533e816d2223e070b30f294 (diff)
QML Settings: fix JS array handling
Before Qt 5.4, JS arrays were passed as QVariantLists. Since Qt 5.4, they are passed as QJSValues instead. Use QJSValue::toVariant() (the same way as QQuickItemView::setModel(QVariant) which was fixed in cf959b4b) to convert JS values to QSettings-compatible variants. Task-number: QTBUG-45316 Change-Id: Icc6f8ad09bfef089d9efcf5b90e3783bb3f73a9f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/settings/qqmlsettings.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/imports/settings/qqmlsettings.cpp b/src/imports/settings/qqmlsettings.cpp
index cd6fcbc718..df67c04654 100644
--- a/src/imports/settings/qqmlsettings.cpp
+++ b/src/imports/settings/qqmlsettings.cpp
@@ -41,6 +41,7 @@
#include <qcoreevent.h>
#include <qsettings.h>
#include <qpointer.h>
+#include <qjsvalue.h>
#include <qdebug.h>
#include <qhash.h>
@@ -241,6 +242,7 @@ public:
void store();
void _q_propertyChanged();
+ QVariant readProperty(const QMetaProperty &property) const;
QQmlSettings *q_ptr;
int timerId;
@@ -295,7 +297,7 @@ void QQmlSettingsPrivate::load()
for (int i = offset; i < count; ++i) {
QMetaProperty property = mo->property(i);
- const QVariant previousValue = property.read(q);
+ const QVariant previousValue = readProperty(property);
const QVariant currentValue = instance()->value(property.name(), previousValue);
if (!currentValue.isNull() && (!previousValue.isValid()
@@ -340,9 +342,10 @@ void QQmlSettingsPrivate::_q_propertyChanged()
const int count = mo->propertyCount();
for (int i = offset; i < count; ++i) {
const QMetaProperty &property = mo->property(i);
- changedProperties.insert(property.name(), property.read(q));
+ const QVariant value = readProperty(property);
+ changedProperties.insert(property.name(), value);
#ifdef SETTINGS_DEBUG
- qDebug() << "QQmlSettings: cache" << property.name() << ":" << property.read(q);
+ qDebug() << "QQmlSettings: cache" << property.name() << ":" << value;
#endif
}
if (timerId != 0)
@@ -350,6 +353,15 @@ void QQmlSettingsPrivate::_q_propertyChanged()
timerId = q->startTimer(settingsWriteDelay);
}
+QVariant QQmlSettingsPrivate::readProperty(const QMetaProperty &property) const
+{
+ Q_Q(const QQmlSettings);
+ QVariant var = property.read(q);
+ if (var.userType() == qMetaTypeId<QJSValue>())
+ var = var.value<QJSValue>().toVariant();
+ return var;
+}
+
QQmlSettings::QQmlSettings(QObject *parent)
: QObject(parent), d_ptr(new QQmlSettingsPrivate)
{