Pass a parent pointer to the Animation instance to avoid memory leak

The leak is just on termination, but we should show good practices in
our examples

Pick-to: 6.4 6.3 6.2
Change-Id: I39abb7545d3c68a1a537b865ba3fcb5e60c22fbf
Reviewed-by: Venugopal Shivashankar <Venugopal.Shivashankar@qt.io>
This commit is contained in:
Jan Arve Sæther 2022-09-08 12:56:24 +02:00
parent f2a2800b37
commit 30947c7fd4
2 changed files with 3 additions and 3 deletions

View File

@ -15,8 +15,8 @@ public:
CirclePath, CirclePath,
NPathTypes NPathTypes
}; };
Animation(QObject *target, const QByteArray &prop) Animation(QObject *target, const QByteArray &prop, QObject *parent = nullptr)
: QPropertyAnimation(target, prop) : QPropertyAnimation(target, prop, parent)
{ {
setPathType(LinearPath); setPathType(LinearPath);
} }

View File

@ -35,7 +35,7 @@ Window::Window(QWidget *parent)
m_scene.addItem(m_item); m_scene.addItem(m_item);
m_ui.graphicsView->setScene(&m_scene); m_ui.graphicsView->setScene(&m_scene);
m_anim = new Animation(m_item, "pos"); m_anim = new Animation(m_item, "pos", this);
m_anim->setEasingCurve(QEasingCurve::OutBounce); m_anim->setEasingCurve(QEasingCurve::OutBounce);
m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce)); m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));