PDA

View Full Version : is content of QPixmap copied with QGraphicsPixmapItem::setPixmap ?



franki
17th July 2013, 17:55
Hi,

This is probably very lame question,
I have a QMap<int,MyStruct*> in MyStruct there is QPixmap variable and two pointers to objects derived from QGraphicsPixmapItem.
If I load image to QPixmap, and then in constructor of these QGraphicsPixmapItem I pass QPixmap from MyStruct, is pixmap in fact copied to QGraphicsPixmapItem, and thus increase memory allocation?

I'm asking because these QPixmap's are jpegs around 1MB in size, and QMap has around 10 MyStruct's which gives roughly 20 QGraphicsPixmapItem's and 10 QPixmap's and I want to run this application on Android, so I wonder, should I destroy there QGraphicsPixmapItem's ? and create them only when I need to make them visible, or I just worry to much?

And how to really free QPixmap if this is simple variable which I hold in MyStruct, QGraphicsPixmapItem's are allocated with "new", so I can simply "delete" them.

best regards
Marek

ChrisW67
17th July 2013, 22:51
If I load image to QPixmap, and then in constructor of these QGraphicsPixmapItem I pass QPixmap from MyStruct, is pixmap in fact copied to QGraphicsPixmapItem,
The QPixmap is copied

and thus increase memory allocation?
No, the bulk data is not duplicated. QPixmap copies implicitly share the same data until you modify a copy ( which results in duplication of the bulk image data).



And how to really free QPixmap if this is simple variable which I hold in MyStruct, QGraphicsPixmapItem's are allocated with "new", so I can simply "delete" them.
Assign a null (default constructed) QPixmap to free the bulk data