Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] dragdroprobot example will cause a memory leak?
Qt 6.11 is out! See what's new in the release blog

[Moved] dragdroprobot example will cause a memory leak?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    youni
    wrote on last edited by
    #1

    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);
    

    ::::::::::::::::

    }

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved