Report correct state change when destroying QAbstractAnimation

Change-Id: Ibe5310e20268d1baa5b329a4d02a3dc38d875008
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-06-20 12:46:30 +02:00
parent 25eb0408a6
commit 7940791f47
2 changed files with 16 additions and 1 deletions

View File

@ -1061,7 +1061,7 @@ QAbstractAnimation::~QAbstractAnimation()
if (d->state != Stopped) {
QAbstractAnimation::State oldState = d->state;
d->state = Stopped;
emit stateChanged(oldState, d->state);
emit stateChanged(d->state, oldState);
if (oldState == QAbstractAnimation::Running)
QAnimationTimer::unregisterAnimation(this);
}

View File

@ -83,6 +83,21 @@ void tst_QAbstractAnimation::destruction()
{
TestableQAbstractAnimation *anim = new TestableQAbstractAnimation;
delete anim;
// Animations should stop when deleted
auto *stopWhenDeleted = new TestableQAbstractAnimation;
QAbstractAnimation::State lastOldState, lastNewState;
QObject::connect(stopWhenDeleted, &QAbstractAnimation::stateChanged,
[&](QAbstractAnimation::State newState, QAbstractAnimation::State oldState) {
lastNewState = newState;
lastOldState = oldState;
});
stopWhenDeleted->start();
QCOMPARE(lastOldState, QAbstractAnimation::Stopped);
QCOMPARE(lastNewState, QAbstractAnimation::Running);
delete stopWhenDeleted;
QCOMPARE(lastOldState, QAbstractAnimation::Running);
QCOMPARE(lastNewState, QAbstractAnimation::Stopped);
}
void tst_QAbstractAnimation::currentLoop()