Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Not able to add a list property to QML element

Not able to add a list property to QML element

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 11.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jess0pher
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jess0pher
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jess0pher
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jess0pher
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              petzold
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                petzold
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved