Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.5.5-1, 6.7.0
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
- Build and run the attached project
- Click the "Animate" button (to run the animation)
- Toggle the "Ascending" switch (to swap startValue and endValue)
- Repeat steps #2 and #3 a few times
Part 2: Inconsistent values
- Build and run the attached project
- Toggle the "Ascending" switch a few times (to swap startValue and endValue)
- Click the "Animate" button (to run the animation)
- 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
Gerrit Reviews
For Gerrit Dashboard: QTBUG-125586 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
582745,2 | Fix QVariantAnimation the current value unexpected changes | dev | qt/qtbase | Status: NEW | +1 | -1 |