From c21803201a607dabc1d5a9345004d8f5dbc02d25 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 20 May 2009 11:42:25 +0200 Subject: Fix an issue that made appear warnings when the target of a property animation was destroyed The problem was that we were not really detecting when the target was destroyed. So we weren't able to unregister it from the global internal hash we have in QPropertyAnimation. This happens if an animation is running and the target object is destroyed. --- src/corelib/animation/qpropertyanimation.cpp | 27 +++++++++++++++++++++++++++ src/corelib/animation/qpropertyanimation.h | 1 + src/corelib/animation/qpropertyanimation_p.h | 5 +++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 1755aa7..10fe8a2 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -146,6 +146,14 @@ void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue) } } +void QPropertyAnimationPrivate::_q_targetDestroyed() +{ + Q_Q(QPropertyAnimation); + //we stop here so that this animation is removed from the global hash + q->stop(); + target = 0; +} + /*! Construct a QPropertyAnimation object. \a parent is passed to QObject's constructor. @@ -188,12 +196,25 @@ QObject *QPropertyAnimation::targetObject() const Q_D(const QPropertyAnimation); return d->target; } + void QPropertyAnimation::setTargetObject(QObject *target) { Q_D(QPropertyAnimation); if (d->target == target) return; + if (d->state != QAbstractAnimation::Stopped) { + qWarning("QPropertyAnimation::setTargetObject: you can't change the target of a running animation"); + return; + } + + //we need to get notified when the target is destroyed + if (d->target) + disconnect(d->target, SIGNAL(destroyed()), this, SLOT(_q_targetDestroyed())); + + if (target) + connect(target, SIGNAL(destroyed()), SLOT(_q_targetDestroyed())); + d->target = target; d->hasMetaProperty = 0; d->updateMetaProperty(); @@ -211,9 +232,15 @@ QByteArray QPropertyAnimation::propertyName() const Q_D(const QPropertyAnimation); return d->propertyName; } + void QPropertyAnimation::setPropertyName(const QByteArray &propertyName) { Q_D(QPropertyAnimation); + if (d->state != QAbstractAnimation::Stopped) { + qWarning("QPropertyAnimation::setPropertyName: you can't change the property name of a running animation"); + return; + } + d->propertyName = propertyName; d->hasMetaProperty = 0; d->updateMetaProperty(); diff --git a/src/corelib/animation/qpropertyanimation.h b/src/corelib/animation/qpropertyanimation.h index dbd118c..5b06bd2 100644 --- a/src/corelib/animation/qpropertyanimation.h +++ b/src/corelib/animation/qpropertyanimation.h @@ -75,6 +75,7 @@ protected: void updateCurrentValue(const QVariant &value); void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); + Q_PRIVATE_SLOT(d_func(), void _q_targetDestroyed()); private: Q_DISABLE_COPY(QPropertyAnimation) Q_DECLARE_PRIVATE(QPropertyAnimation) diff --git a/src/corelib/animation/qpropertyanimation_p.h b/src/corelib/animation/qpropertyanimation_p.h index 9d9dd31..b51d039 100644 --- a/src/corelib/animation/qpropertyanimation_p.h +++ b/src/corelib/animation/qpropertyanimation_p.h @@ -55,7 +55,6 @@ #include "qpropertyanimation.h" #include -#include #include "qvariantanimation_p.h" @@ -70,7 +69,9 @@ public: { } - QPointer target; + void _q_targetDestroyed(); + + QObject *target; //for the QProperty QMetaProperty property; -- cgit v0.12