Results 1 to 2 of 2

Thread: A c++ newbie question about memory leak ( QGraphicsPixmapItem )

  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default A c++ newbie question about memory leak ( QGraphicsPixmapItem )

    Hi.

    I'm newbie on programming and have a doubt about the memory leaks.

    I have a QGraphicsScene with a parent, this is ok, it will be erased when the app closes or the parent is distroyed, but i want to add QGraphicsPixmapItem.
    Qt Code:
    1. void eMain::load_art() {
    2.  
    3. QGraphicsPixmapItem *pItem = new QGraphicsPixamItem();
    4. pItem->setPixmap(QPixmap(strToPixmapPath));
    5. myScene->setSceneRect(0, 0, QPixmap(strToPixmapPath).width(), QPixmap(strToPixmapPath).height());
    6. myScene->addItem(pItem);
    7. }
    To copy to clipboard, switch view to plain text mode 

    That QGraphicsPixmapItem is a memory leak, right? Could i set a parent QGraphicsItem or something?

    Thanks and sotty if is a stupid question.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: A c++ newbie question about memory leak ( QGraphicsPixmapItem )

    QGraphicsScene::addItem():
    Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2011, 22:05
  2. Question about layout and memory leak
    By franco.amato in forum Newbie
    Replies: 3
    Last Post: 15th October 2010, 18:50
  3. About the question of QTcpServer, there memory leak
    By hxj830088 in forum Qt Programming
    Replies: 4
    Last Post: 24th December 2009, 03:27
  4. QList<pointer>::takeFirst() and memory leak question
    By AcerExtensa in forum Qt Programming
    Replies: 3
    Last Post: 9th July 2009, 13:20
  5. memory leak question
    By cool_qt in forum General Programming
    Replies: 3
    Last Post: 20th January 2009, 07:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.