gpt4 book ai didi

c++ - QPropertyAnimation 使用QParallelAnimationGroup 时自动删除?

转载 作者:行者123 更新时间:2023-11-30 03:28:08 26 4
gpt4 key购买 nike

根据以下代码片段,我对QPropertyAnimationQParallelAnimationGroup 有疑问:

// Create the opacity animation
QPropertyAnimation *animation1 = new QPropertyAnimation(notification, "windowOpacity");
animation1->setDuration(animationDuration);
animation1->setStartValue(startOpacity);
animation1->setEndValue(endOpacity);
animation1->setEasingCurve(QEasingCurve::InBack);

// Create the position animation
QPropertyAnimation *animation2 = new QPropertyAnimation(notification, "pos");
animation2->setDuration(animationDuration);
animation2->setStartValue(startPos);
animation2->setEndValue(endPos);

// Create the animation group
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(animation1);
group->addAnimation(animation2);
group->start(QAbstractAnimation::DeleteWhenStopped);

connect(group, SIGNAL(finished()), group, SLOT(deleteLater()), Qt::UniqueConnection);
  1. 关于 QAbstractAnimation::DeleteWhenStopped 常量,Qt documentation说:

The animation will be automatically deleted when stopped.

这是否意味着指针(animation1animation2)将被自动删除?或者我仍然需要“手动”删除它们(可能使用如下信号和插槽)?

connect(animation1, SIGNAL(finished()), animation1, SLOT(deleteLater()), Qt::UniqueConnection);
connect(animation2, SIGNAL(finished()), animation2, SLOT(deleteLater()), Qt::UniqueConnection);

我正在使用 Qt 5.3。

最佳答案

是的,两者都被摧毁了。

animation1->setProperty("nameObj", "animation1");
animation2->setProperty("nameObj", "animation2");
group->setProperty("nameObj", "group");

connect(animation1, SIGNAL(destroyed(QObject*)), this, SLOT(OnAnimationDestroyed(QObject*)));
connect(animation2, SIGNAL(destroyed(QObject*)), this, SLOT(OnAnimationDestroyed(QObject*)));
connect(group, SIGNAL(destroyed(QObject*)), this, SLOT(OnAnimationDestroyed(QObject*)));

group->start(QAbstractAnimation::DeleteWhenStopped);

void MyObj::OnAnimationDestroyed(QObject* obj)
{
qDebug() << "Destroyed: " << obj->property("nameObj").toString();
}

结果是:

Destroyed:  "group"

Destroyed: "animation1"

Destroyed: "animation2"

关于c++ - QPropertyAnimation 使用QParallelAnimationGroup 时自动删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46838336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com