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

Assignment to list property yields unexpected result

    XMLWordPrintable

Details

    • 85554f7f262ff5aae15562b11c6d08bcc03c961f

    Description

      Run this code and click on the screen:

      import QtQuick 1.0
      
      Item {
          id: root
          width: 640
          height: 480
      
          property list<Rectangle> rects: [
              Rectangle { width: 100; height: 100 },
              Rectangle { width: 200; height: 100 },
              Rectangle { width: 300; height: 100 },
              Rectangle { width: 400; height: 100 }
          ]
      
          Item {
              id: item
              property list<Rectangle> theRects
              onTheRectsChanged: {
                  print("New list length: " + theRects.length);
                  if(theRects.length > 0)
                      print("Last item's width: " + theRects[theRects.length-1].width);
      
              }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: item.theRects = root.rects
          }
      }
      

      The expected output to the debug console is this:

      New list length: 4
      Last item's width: 400
      

      But instead the output is:

      New list length: 0
      New list length: 1
      file:///home/mathias/dev/gitorious/mathiasm-qt-components/tools/StretchBench.qml:23: TypeError: Result of expression 'theRects[theRects.length-1]' [null] is not an object.
      

      Attachments

        Issue Links

          Activity

            People

              chriadam Christopher Adams (closed Nokia identity) (Inactive)
              mathiasm Mathias Malmqvist
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: