Target deletion when animation is finished
How do I delete the target object of QProperyAnimation when animation is finished?
Here is a sample code snippet that I am trying to use.
QPropertyAnimation *animation = new QPropertyAnimation(this);
animation->setStartValue(QRect(0, label->height(), label->width(), label->height()));
animation->setEndValue( QRect(1680, label->height(), label->width(), label->height()));
connect(animation, signal( finished() ), this, slot( DeleteTarget(label) );
As you have noticed I want delete my target object, here label, when the animation is finished. But I realized that I can not pass "label" as a parameter to the slot DeleteTarget().
So how do I delete the target, the label, after the animation is completed? I don't think I can delete the target after calling animation->start(), as the animation requires it.
Appreciate your response.
Edit: Added code tags (@) around the code. Please do that yourself next time; Andre
From the top of my head.
QPropertyAnimation animation = qobject_cast<QPropertyAnimation>(sender());
Thanks for the response. If I call
connect(animation,SIGNAL(finished()) ,label, SLOT(deleteLater()));
When is the label deleted?
- Is it when the finished signal is emitted or
- later, when the program exits?
From the documentation. Try having a look at it sometimes. :-P
void QObject::deleteLater () [slot]
Schedules this object for deletion.
The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started.