Why dump in QAbstractAnimation::start
-
void func() { ... connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { pAnimationTextGeometry->start(); }); ... pAnimationBannerOpacity->start(); }
I want a Animation start when another Animation end.
But I dump In QAbstractAnimation::start.
Can anyone tell me why. Thanks. -
void func() { ... connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { pAnimationTextGeometry->start(); }); ... pAnimationBannerOpacity->start(); }
I want a Animation start when another Animation end.
But I dump In QAbstractAnimation::start.
Can anyone tell me why. Thanks.@Toocold said in Why dump in QAbstractAnimation::start:
But I dump In QAbstractAnimation::start
What do you mean with that? The second animation does not start if the first one finishes?
-
@Toocold said in Why dump in QAbstractAnimation::start:
But I dump In QAbstractAnimation::start
What do you mean with that? The second animation does not start if the first one finishes?
-
void func() { ... connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { pAnimationTextGeometry->start(); }); ... pAnimationBannerOpacity->start(); }
I want a Animation start when another Animation end.
But I dump In QAbstractAnimation::start.
Can anyone tell me why. Thanks. -
@Toocold do you happen to have called
start(QAbstractAnimation::DeleteWhenStopped)
instead ofstart(QAbstractAnimation::KeepWhenStopped)
@J-Hilk
no.pAnimationBannerOpacity = new QPropertyAnimation(m_pIntroduction->pOpacityBanner, "opacity", m_pIntroduction->pLableBanner); pAnimationTextGeometry = new QPropertyAnimation(m_pIntroduction->pLableText, "geometry", m_pIntroduction->pLableBanner);
I just set parent to them.
The Animation like some's Opacity from 0 to 1, and then play Geometry Animation. -
@J-Hilk
no.pAnimationBannerOpacity = new QPropertyAnimation(m_pIntroduction->pOpacityBanner, "opacity", m_pIntroduction->pLableBanner); pAnimationTextGeometry = new QPropertyAnimation(m_pIntroduction->pLableText, "geometry", m_pIntroduction->pLableBanner);
I just set parent to them.
The Animation like some's Opacity from 0 to 1, and then play Geometry Animation.@Toocold I suggest to use debugger and position a breakpoint at
pAnimationTextGeometry->start();
and check what happens when you execute that line. Is, fir example, pAnimationTextGeometry really pointing to an existing instance?
-
@Toocold I suggest to use debugger and position a breakpoint at
pAnimationTextGeometry->start();
and check what happens when you execute that line. Is, fir example, pAnimationTextGeometry really pointing to an existing instance?
@jsulm
In this Functionvoid QAbstractAnimation::start(DeletionPolicy policy) { Q_D(QAbstractAnimation); if (d->state == Running) return; d->deleteWhenStopped = policy; d->setState(Running); }
My program crashed because of "d" is Null.
But it's strange, the QPropertyAnimation instance is newed in heap.
And I set theirs' parent Null now and start(QAbstractAnimation::KeepWhenStopped) instead of. -
@jsulm
In this Functionvoid QAbstractAnimation::start(DeletionPolicy policy) { Q_D(QAbstractAnimation); if (d->state == Running) return; d->deleteWhenStopped = policy; d->setState(Running); }
My program crashed because of "d" is Null.
But it's strange, the QPropertyAnimation instance is newed in heap.
And I set theirs' parent Null now and start(QAbstractAnimation::KeepWhenStopped) instead of.@Toocold said in Why dump in QAbstractAnimation::start:
My program crashed because of "d" is Null.
Then the object is invalid/not initialised.
-
@Toocold said in Why dump in QAbstractAnimation::start:
My program crashed because of "d" is Null.
Then the object is invalid/not initialised.
connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { if (pAnimationTextGeometry) { pAnimationTextGeometry->start(QAbstractAnimation::KeepWhenStopped); } });
But I checked it before invoking the function.
And It can work by added to QSequentialAnimationGroup Class. -
connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { if (pAnimationTextGeometry) { pAnimationTextGeometry->start(QAbstractAnimation::KeepWhenStopped); } });
But I checked it before invoking the function.
And It can work by added to QSequentialAnimationGroup Class.@Toocold said in Why dump in QAbstractAnimation::start:
if (pAnimationTextGeometry)
This only checks whether the pointer is not nullptr, but it still can point to not allocated memory.
-
connect(pAnimationBannerOpacity, &QPropertyAnimation::finished, [&] { if (pAnimationTextGeometry) { pAnimationTextGeometry->start(QAbstractAnimation::KeepWhenStopped); } });
But I checked it before invoking the function.
And It can work by added to QSequentialAnimationGroup Class.@Toocold
Because you cannot afford to deference a pointer if it's pointing to garbage, if you use a debugger as @jsulm suggested you can look in its "watch" window at whatpAnimationTextGeometry
actually points to. It's not foolproof, but if what the debugger shows doesn't look good, it's probably a bad pointer. -
@Toocold said in Why dump in QAbstractAnimation::start:
if (pAnimationTextGeometry)
This only checks whether the pointer is not nullptr, but it still can point to not allocated memory.
-
@jsulm @JonB
You can try this program, it will crash.void func() { QLabel* p1 = new QLabel; QLabel* p2 = new QLabel; QPropertyAnimation* pA1; QPropertyAnimation* pA2; p1->setText("123"); p2->setText("456"); p1->setGeometry(QRect(0, 0, 0, 0)); p2->setGeometry(QRect(0, 0, 0, 0)); p1->show(); p2->show(); pA1 = new QPropertyAnimation(p1, "geometry"); pA2 = new QPropertyAnimation(p2, "geometry"); pA1->setDuration(1000); pA1->setStartValue(QRect(0, 0, 0, 0)); pA1->setEndValue(QRect(660, 660, 60, 60)); pA2->setDuration(1000); pA2->setStartValue(QRect(0, 0, 0, 0)); pA2->setEndValue(QRect(330, 330, 30, 30)); QObject::connect(pA1, &QPropertyAnimation::finished, [&] { pA2->start(); }); pA1->start(); } int main(int argc, char** argv) { QApplication a(argc, argv); func(); return a.exec(); }
-
@Toocold said in Why dump in QAbstractAnimation::start:
QObject::connect(pA1, &QPropertyAnimation::finished, [&] {
C++ basics - you catch the variables by reference...
-
@Toocold said in Why dump in QAbstractAnimation::start:
QObject::connect(pA1, &QPropertyAnimation::finished, [&] {
C++ basics - you catch the variables by reference...
@Christian-Ehrlicher
Yeah...I didn't notice it.
Thank you. -
@Christian-Ehrlicher
Yeah...I didn't notice it.
Thank you.@Toocold Then please mark this topic as solved, thx.