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

    • d489f2f6549a86b3949004d1c8ec68487fc2adb7

      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.

        For Gerrit Dashboard: QTBUG-21549
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes