Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.12.2
Description
Assuming an item, ExampleItem has a list-type (e.g. backed by QQmlListProperty) property, called "things", we can, in qml, bind it to a list of objects:
ExampleItem { things: [ Thing { name: "name1" }, Thing { name: "name2" } ] }
However, if we want to conditionally assign different lists based on another property, it doesn't appear to work:
ExampleItem { property bool someCondition things: someCondition ? [ Thing { name: "name1" }, Thing { name: "name2" } ] : [ Thing { name: "name3" } ] }
Expected token `,' Expected token `,' Expected token `,'
At first I thought that maybe you couldn't use a conditional in a list property binding. However, the following does work:
ExampleItem { property bool someCondition property var thing1: Thing { name: "name1" } property var thing2: Thing { name: "name2" } property var thing3: Thing { name: "name3" } things: someCondition ? [ thing1 , thing2 ] : [ thing3 ] }
I can only assume that conditional bindings with lists of object for list properties do work, but that the QML/Javascript parser doesn't handle the syntax properly if you try to declare the objects inline.
Note that the example with "property var thing1" isn't quite the same as was intended, as it always creates all possible list contents, instead of just creating those which are currently in the list (thing1 and thing2 are created even when someCondition is false).