From 5f49b2b3bb30678a26341e1f45e0cfd6a6fd2c57 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 11 May 2017 17:19:14 +0200 Subject: 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 --- src/imports/settings/qqmlsettings.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/imports') 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 #include #include +#include #include #include @@ -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()) + var = var.value().toVariant(); + return var; +} + QQmlSettings::QQmlSettings(QObject *parent) : QObject(parent), d_ptr(new QQmlSettingsPrivate) { -- cgit v1.2.3