PDA

View Full Version : A c++ newbie question about memory leak ( QGraphicsPixmapItem )



aguayro
4th November 2012, 01:13
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.


void eMain::load_art() {

QGraphicsPixmapItem *pItem = new QGraphicsPixamItem();
pItem->setPixmap(QPixmap(strToPixmapPath));
myScene->setSceneRect(0, 0, QPixmap(strToPixmapPath).width(), QPixmap(strToPixmapPath).height());
myScene->addItem(pItem);
}


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

Thanks and sotty if is a stupid question.

ChrisW67
5th November 2012, 08:39
QGraphicsScene::addItem():


Adds or moves the item and all its childen to this scene. This scene takes ownership of the item.