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

Array.prototype.forEach unreliable when called on Qt lists

    XMLWordPrintable

Details

    • 7b3eb5373a0d3611c5a83379c5eb59505cc5c074 (qtdeclarative)

    Description

      Using Array.prototype.forEach() on a Qt list does not give stable result.

      The following test passes with a success rate of about 95% on Windows 7, but fails randomly. If I replace forEach with a for loop, it always passes.

      import QtQuick 2.2
      import QtTest 1.0
      
      Item {
          Column {
              id: column
      
              Text { text: "1" }
              Text { text: "2" }
              Text { text: "3" }
          }
      
          TestCase {
              name: "ArrayPrototypeForEachOnList"
      
              function test_forEach() {
                  var count = 0;
                  Array.prototype.forEach.call(column.children, function(child) { ++count; });
                  compare(count, 3);
              }
          }
      }
      

      In addition, there also seem to be platform differences. While the test above runs fine on Mac OS, the following program always logs "count: 0" to the console when I click into its window on Mac OS, whereas it correctly logs "count: 3" Windows:

      import QtQuick 2.0
      
      Rectangle {
          width: 360
          height: 360
          Column {
              id: item
      
              Text { text: "Hello World 1" }
              Text { text: "Hello World 2" }
              Text { text: "Hello World 3" }
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  var count = 0;
                  Array.prototype.forEach.call(item.children, function(child) {
                      ++count;
                  });
                  console.log("count:" + count);
              }
          }
      }
      

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            che Carsten Henßinger
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes