Results 1 to 2 of 2

Thread: is content of QPixmap copied with QGraphicsPixmapItem::setPixmap ?

  1. #1
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default is content of QPixmap copied with QGraphicsPixmapItem::setPixmap ?

    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

  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: is content of QPixmap copied with QGraphicsPixmapItem::setPixmap ?

    Quote Originally Posted by franki View Post
    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

  3. The following user says thank you to ChrisW67 for this useful post:

    franki (18th July 2013)

Similar Threads

  1. slow ui.cameraView->setPixmap(QPixmap::fromImage(img));
    By bhamadicharef in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th September 2012, 16:45
  2. Replies: 2
    Last Post: 28th October 2011, 07:46
  3. QGraphicsPixmapItem to QPixmap to QImage and back again!
    By bruceariggs in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2011, 14:08
  4. QGraphicsPixmapItem::setPixmap() renders very slow
    By hakiim35 in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2011, 13:38
  5. Replies: 2
    Last Post: 15th March 2010, 10:03

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.