Not able to add a list property to QML element
-
wrote on 19 Sept 2011, 01:59 last edited by
This seems like valid QML to me
@Rectangle {
width: 360
height: 360Image { id: charsprite property list<string> frames: ["qrc:/chrsprite/walk1.png","qrc:/chrsprite/walk2.png"] property int frame: 1 height: 200 width: 100 source: frames[frame] } Timer { interval: 500 running: true repeat: true onTriggered: charsprite.frame = charsprite.frame+1 % 2 }
}@
But whenever I run the code, the QML parser gives the following error:
@...qml/MiniGame/main.qml:10:40: Expected a qualified name id
property list<string> frames: ["qrc:/chrsprite/walk1.png","qrc:/chrsprite/walk2.png"] @What am I doing wrong here in my declaration/initialization of the charsprite.frames property?
-
wrote on 19 Sept 2011, 02:04 last edited by
and position 10:40 is "qrc:/charsprite/walk1.png", fyi
-
wrote on 19 Sept 2011, 02:35 last edited by
Well it would be nice to have the type safety, but one can use variant instead of list<string>, so I'm just going with that for now.
-
wrote on 19 Sept 2011, 04:56 last edited by
HI,
From memory currently only lists of object types (and not basic types like strings) are supported using the property list<type> syntax. You might want to check http://bugreports.qt.nokia.com to see if there is an existing suggestion for this, or add one if there isn't.
Regards,
Michael -
wrote on 19 Sept 2011, 12:10 last edited by
Yup, thats it. I guess the documentation does sneak that in (the word object is used, but its not specific about what sort of object). So the only thing i can see actually erroneous about the behavior is how and where the parser reports it. It should be reporting it in the LHS, since the type itself is malformed. Thanks Michael.
-
wrote on 2 Dec 2014, 13:20 last edited by
i know long time ago. but for the next
try that.property variant frames: ["qrc:/chrsprite/walk1.png","qrc:/chrsprite/walk2.png"]
i tested it with int and it works fine.
-
wrote on 2 Dec 2014, 13:20 last edited by
i know long time ago. but for the next
try that.property variant frames: ["qrc:/chrsprite/walk1.png","qrc:/chrsprite/walk2.png"]
i tested it with int and it works fine.