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

Behavior gets called even when the property doesn't change (when the property is a combination of other properties)

    XMLWordPrintable

Details

    • d489f2f6549a86b3949004d1c8ec68487fc2adb7

    Description

      When Behavior depends on a property which in turn depends on other parameters, the Behavior gets called whenever the other parameters change, even when the property itself doesn't change.

      In the uploaded example, Behavior depends on a boolean property which depends on whether a number property is positive or negative.

      import QtQuick 1.0
      
      Rectangle {
          width: 360
          height: 360
      
          color: "blue";
      
          property int number: -50;
          property bool positive: number > 0;
      
          Behavior on positive {
              ScriptAction {
                  script: console.log("foo");
              }
          }
      
          Component.onCompleted: {
              for (var i = 0; i < 100; i++) {
                  number += 1;
              }
          }
      }
      

      Expected result: Behavior on positive {} is called only once
      Result: Behavior on positive{} is called 100 times.

      The strange thing is that even though the Behavior change is called, if a slot onPositiveChanged is added it's not called. (so it does make a check Behavior doesn't)

      Although I agree that may not be the purpose of Behavior (that kind of thing is somewhat the purpose of States), some other cases might be trickier, and if this bug is normal it should be at least specified in the documentation.

      Attachments

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

        Activity

          People

            mbrasser Michael Brasser
            coyotte508 coyotte508
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes