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

QML is not deterministic

XMLWordPrintable

      The following code produces different result on different runs:

      import Qt 4.7
      
      
      Rectangle {
          width: 100
          height: 62
      
          property int a
          property int b : a
          property int c : a + b
          property bool d : c === 1
      
          onAChanged: console.log("a: " + a)
          onBChanged: console.log("b: " + b)
          onCChanged: console.log("c: " + c)
          onDChanged: console.log("d: " + d)
      
          Component.onCompleted: { a = 1; Qt.quit(); }
      }
      

      One would easily be fooled to think property d never becomes true just by looking at the code, but sometimes the "d" property is transiently true, depending on the evaluation order of the bindings which is not fixed from run to run. So, all qml apps must be written so that the code is robust against changes in evaluation order, a fact that is probably mentioned in some documentation. However, looking at the above example, how is it possible to ensure the application does not implicitly rely on the evaluation order if logic is more involved?

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

            aakenned Aaron Kennedy
            mikkohar Mikko Harju
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes