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

QVariantAnimation: currentValue should not change when calling setStartValue() and setEndValue()

    XMLWordPrintable

Details

    Description

      Problem summary
      QVariantAnimation::currentValue changes when we call setStartValue() and setEndValue(). This can cause wrong outcomes for calculations that are bound to this value.

       

      Test description
      The attached project contains a simple class, TestObject, with a property that is controlled by a QPropertyAnimation:

      Q_PROPERTY(qreal number MEMBER m_number NOTIFY numberChanged)
      

       

      Then, we monitor the value of both TestObject::number and QVariantAnimation::currentValue while swapping the animation's startValue/endValue and while running the animation. Results of interest are plotted on a chart as well as printed to the console.

       

      Steps to reproduce
      Part 1: Glitches in value

      1. Build and run the attached project
      2. Click the "Animate" button (to run the animation)
      3. Toggle the "Ascending" switch (to swap startValue and endValue)
      4. Repeat steps #2 and #3 a few times

       

      Part 2: Inconsistent values

      1. Build and run the attached project
      2. Toggle the "Ascending" switch a few times (to swap startValue and endValue)
      3. Click the "Animate" button (to run the animation)
      4. Toggle the "Ascending" switch a few times again

       

      Outcomes
      Part 1: Glitches in value

      • The blue "number" line is a nice triangular wave. The value of "number" does not change when calling setStartValue() and setEndValue(). (Expected)
      • The green "currentValue" line mostly looks like the blue "number" line, except that it contsins vertical glitches (value jumps) between animations. The value of "currentValue" jumps when calling setStartValue() and setEndValue(). (Not expected)
      • Each time we do step #3, QVariantAnimation::valueChanged is emitted twice - once to change it to an Invalid variant, and again to change it to the new endValue (Not expected):
        currentValue changed while animation is stopped. New value: QVariant(Invalid)
        currentValue changed while animation is stopped. New value: QVariant(int, 100)
        

       

      Part 2: Inconsistent values

      • (step #2) When the program first starts, toggling the switch sets currentValue = startValue (Reasonably expected?)
      • (step #4) After the animation has run at least once, toggling the switch sets currentValue = endValue (Not expected)

       

      Workaround
      As the attached test shows, QPropertyAnimation filters out these unexpected changes. Instead of binding directly to QVariantAnimation::currentValue, users can apply QPropertyAnimation to a Q_PROPERTY and bind to that instead.

      Attachments

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

        Activity

          People

            sadegh Sadegh Taghavi
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change