[Moved] dragdroprobot example will cause a memory leak?
-
When I was studying the example code (dragdroprobot) provided by QT, I found that headAnimation and upperLeftArmAnimation (I did not copy all the codes there) were created on the heap but did not find where those were deleted, so those would definately cause a memory leak?
Can somebody take a look at this issue and fix them if I am correct.
Thanks.
Robot::Robot()
{:::::::::::::::::::::::::::::::::::::::::::: QGraphicsItemAnimation *headAnimation = new QGraphicsItemAnimation; headAnimation->setItem(headItem); headAnimation->setTimeLine(timeLine); headAnimation->setRotationAt(0, 20); headAnimation->setRotationAt(1, -20); headAnimation->setScaleAt(1, 1.1, 1.1); QGraphicsItemAnimation *upperLeftArmAnimation = new QGraphicsItemAnimation; upperLeftArmAnimation->setItem(upperLeftArmItem); upperLeftArmAnimation->setTimeLine(timeLine); upperLeftArmAnimation->setRotationAt(0, 190); upperLeftArmAnimation->setRotationAt(1, 180);
::::::::::::::::
}
-
Please use code tags:
@Robot::Robot()
{(...)
QGraphicsItemAnimation *headAnimation = new QGraphicsItemAnimation;
headAnimation->setItem(headItem);
headAnimation->setTimeLine(timeLine);
headAnimation->setRotationAt(0, 20);
headAnimation->setRotationAt(1, -20);
headAnimation->setScaleAt(1, 1.1, 1.1);QGraphicsItemAnimation *upperLeftArmAnimation = new QGraphicsItemAnimation; upperLeftArmAnimation->setItem(upperLeftArmItem);
upperLeftArmAnimation->setTimeLine(timeLine);
upperLeftArmAnimation->setRotationAt(0, 190);
upperLeftArmAnimation->setRotationAt(1, 180);}@
Otherwise: good question. It seems to me that the animations should be created with some kind of parent.