Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.4.0
-
None
-
Windows 7 SP1 x64
MSVC2010 x64
QtCreator 3.3.0
Qt 5.4.0-x64 MSVC2010 (self-compiled from git tag v5.4.0)
-
e9398ba4e7512ae53e617dcb3a3577c14b43fe7d
Description
In the process of upgrading our large hybrid C++/QML1 application from Qt 5.3.2 to 5.4.0, I've noticed that some functionality was broken and that several errors were now logged. Those errors were all a mix of:
"Unable to assign QVariantList to QList<QObject*>"
and
"Error: Cannot assign QVariantList to QList<QObject*>"
After investigation, I found that in 5.4.0, in Qml 1, assigning an empty array to a Q_PROPERTY(QList<QObject*> ...) now fails with the above errors on binding update / assignment.
Thus, given a type "TestObject" with a "prop" QList<QObject*> property, the following Qml snippets now all fail unexpectedly:
TestObject { prop: [] }
TestObject { id: obj1 Component.onCompleted: obj1.prop = [] }
TestObject { id: obj1 } TestObject { prop: obj1.prop }
This issue neither occurs on previous Qt or when using Qml 2.
I have found this issue to have been introduced by the following commit in the qtquick1 repository ( see https://codereview.qt-project.org/#/c/91214/ ):
Commit: 9cbb6fab48f10522a012af8e535b1750a553a817 Author: Robert Griebl <robert.griebl@pelagicore.com> 2014-07-31 10:14:03 Committer: Robert Griebl <robert.griebl@pelagicore.com> 2014-08-05 10:48:36 Parent: dcbd6c64049682fb6cff0e73a5fdd979de7642dd (Merge remote-tracking branch 'origin/5.3' into dev) Child: 579b773c39c6542b820f037c9a8133dd7c94d1bb (Fix Flickable mouse grab issue.) Branches: remotes/origin/5.4, remotes/origin/5.4.0, remotes/origin/dev Follows: v5.3.1 Precedes: v5.4.0-alpha1 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>
While this commit introduces desirable behavior of returning arrays of non-QObjects values as pure QVariantLists, it breaks the existing behavior of converting empty arrays as empty QList<QObject*>.
I fixed the issue by modifying the offending change above to return an empty QList<QObject*> when the script value is an array of length 0 and the requested type conversion hint is for QList<QObject*>, as it would do before the change.
I've attached 2 sample applications that demonstrate the issue. The first one (emptyobjectlist) shows a minimal Qml1 application that showcase this issue. The second one (emptyobjectlistsimple) is just standalone app with a main() that shows the issue through QDeclarativeExpressions.