diff options
author | Robert Griebl <robert.griebl@pelagicore.com> | 2014-07-31 16:14:03 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@pelagicore.com> | 2014-08-05 16:48:36 +0200 |
commit | 9cbb6fab48f10522a012af8e535b1750a553a817 (patch) | |
tree | 70a6ae95358775657e18d7b25e9ba4f0c4614174 /src | |
parent | dcbd6c64049682fb6cff0e73a5fdd979de7642dd (diff) | |
download | qtquick1-9cbb6fab48f10522a012af8e535b1750a553a817.tar.gz |
Add handling of value-type lists to QDeclarativeExpression::evaluate()
QDeclarativeExpression::evaluate() converts all arrays to QList<QObject *>,
even if the items cannot be represented by a QObject *. In case of a
string-list, a QList of null-pointers is returned (which isn't very helpful).
This patch makes evaluate() convert arrays, which contain ONLY value-type
items, into a plain QVariantList.
Change-Id: Ib8452cf9dd0241f146955f5de35336f48b9007c1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index c67ea236..3fb3b72f 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -2129,8 +2129,20 @@ QVariant QDeclarativeEnginePrivate::scriptValueToVariant(const QScriptValue &val else if (dc == contextClass) return QVariant(); + bool containsQObjects = false; + + if (val.isArray()) { + int length = val.property(QLatin1String("length")).toInt32(); + for (int ii = 0; ii < length; ++ii) { + if (val.property(ii).isQObject()) { + containsQObjects = true; + break; + } + } + } + // Convert to a QList<QObject*> only if val is an array and we were explicitly hinted - if (hint == qMetaTypeId<QList<QObject *> >() && val.isArray()) { + if (hint == qMetaTypeId<QList<QObject *> >() && val.isArray() && containsQObjects) { QList<QObject *> list; int length = val.property(QLatin1String("length")).toInt32(); for (int ii = 0; ii < length; ++ii) { |