Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9341

Can't push() to QML property Array

    XMLWordPrintable

Details

    Description

      I would expect this to work:

          property var myArray: ["a", "b", "c"]
           property var myPoint: { x: 100, y: 200 };
      
      
      
      function addThreeToArray() {
          for(var i = 0; i < 3; i++) {
              myArray.push("X");
              print("Array length: " + myArray.length + "; items: " + myArray.toString());
          }
          ... similar for myPoint ...
      }
      

      and print
      Array length: 4; items: a,b,c,x
      Array length: 5; items: a,b,c,x,x
      Array length: 6; items: a,b,c,x,x,x

      but it doesn't, it prints
      Array length: 3; items: a,b,c
      Array length: 3; items: a,b,c
      Array length: 3; items: a,b,c

      To get what I want, I have to move the code to a separate .js file (changing the
      property definition to: var myArray = ["a", "b", "c"]; ) and then import it into my QML file.
      Then it works as expected. Don't think I should have to.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            aakenned Aaron Kennedy
            mathiasm Mathias Malmqvist
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes