Results 1 to 4 of 4

Thread: QPixmapCache missing pixmaps

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

    Default QPixmapCache missing pixmaps

    Hi all,

    I'm using QPixmapCache to store some icons (png), icons are then used to display proper pixmap for subclassed QGraphicsPixmapItem.
    QPixmapCache is filled once during application start, then each time when I create new QGraphicsPixmapItem, inside constructor of that item I'm doing:
    Qt Code:
    1. if(!QPixmapCache::find(QString::fromUtf8("icon_%1_state_1").arg(button_type),&pixStandard))
    2. qWarning()<<"ButtonsPixmapItem::ButtonsPixmapItem no pixmap for icon_1_state_1";
    3. if(!QPixmapCache::find(QString::fromUtf8("icon_%1_state2").arg(button_type),&pixShortPress))
    4. qWarning()<<"ButtonsPixmapItem::ButtonsPixmapItem no pixmap for icon_1_state2";
    5. if(!QPixmapCache::find(QString::fromUtf8("icon_%1_state3").arg(button_type),&pixLongPress))
    6. qWarning()<<"ButtonsPixmapItem::ButtonsPixmapItem no pixmap for icon_1_state3";
    7. if(!QPixmapCache::find(QString::fromUtf8("icon_%1_state4").arg(button_type),&pixDisabled))
    8. qWarning()<<"ButtonsPixmapItem::ButtonsPixmapItem no pixmap for icon_1_state4";
    To copy to clipboard, switch view to plain text mode 

    After some time, when I'm deleting and creating 20 or 40 QGraphicsPixmapItems, QPixmapCache seems to remove image from the cache, next time I want to find item in cache, I got "false" from QPixmapCache::find and this message.
    Is that possible that under some conditions QPixmapCache removes data? Can this be caused by deleted QGraphicsPixmapItems that used this pixmap, found earlier by QPixmapCache::find ?
    I'm using Qt 4.8.1 on Linux

    best regards
    Marek

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmapCache missing pixmaps

    Quote Originally Posted by franki View Post
    Is that possible that under some conditions QPixmapCache removes data?
    Well... yeah.... it is a cache, not a dictionary. It has a limited capacity and if the capacity is exceeded, the least recently used data is removed before new data is added to the cache.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: QPixmapCache missing pixmaps

    Yes..., but... as well as I know, I don't insert anything more when app is running...

    Anyway should I change code in such a way that when QPixmapCache::find returns false I'm again loading pixmap with the same key, just to be sure, all needed pixmaps are available?

    best regards
    Marek

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmapCache missing pixmaps

    Quote Originally Posted by franki View Post
    Yes..., but... as well as I know, I don't insert anything more when app is running...
    The cache is global for the whole application so you are sharing it with all Qt code. Try increasing capacity of the cache (which is 10MB on desktop and 2MB on embedded systems by default) and see if it changes anything.

    Anyway should I change code in such a way that when QPixmapCache::find returns false I'm again loading pixmap with the same key, just to be sure, all needed pixmaps are available?
    If you are using the cache then yes, you should be aware it can tell you it doesn't have the data you need. An alternative is to have a private dictionary for your icons based on QHash<QString,QPixmap>.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    franki (17th December 2013)

Similar Threads

  1. QPixmapCache calculating needed cache
    By franki in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2013, 19:00
  2. QPixmap: It is not safe to use pixmaps outside the GUI
    By juergenmw in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2012, 22:54
  3. Problem with QPixmapCache
    By christina123y in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2009, 07:49
  4. need to draw on pixmaps outside of the gui thread
    By Serenius in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 16:22
  5. Hande a *lot* of pixmaps (Qt4.4)
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2008, 10:08

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.