Not able to add a list property to QML element



  • This seems like valid QML to me

    @Rectangle {
    width: 360
    height: 360

    Image {
        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?



  • and position 10:40 is "qrc:/charsprite/walk1.png", fyi



  • 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.



  • 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



  • 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.



  • 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.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.