Results 1 to 4 of 4

Thread: QPixmap caching?

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QPixmap caching?

    Is there is a way to turn off QPixmap caching sometimes?

    In particular, I unzip a jpg file to the same place (made by a QTemporaryFile that I create and delete), and then create QPixmaps off of that same place. However, it appears that the caching mechanism hasn't checked that the files have changed, and so it just reuses the previous pixmap that I had loaded without loading the new one fresh, and so all my QPixmaps show the same image.

    The weird thing is that if I step through the pixmap loading through the debugger, QPixmaps load up correctly.

    Does this even sound correct, or maybe it is something else going on? I have verified that my jpg file is changing though.
    Software Engineer



  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPixmap caching?

    Could you provide a minimal compilable example which reproduces the problem?

  3. #3
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QPixmap caching?

    Well, I found that I am using a very rare case for QPixmap. It seems the QPixmap cache uses a key based on the filename and timestamp (from QFileinfo). Because I was writing to the same filename within the same second, the key was the same, so QPixmap assumed the file is already in the cache and didn't bother loading the file again.

    The annoying part is that QTemporaryFile (calls mktemp() on windows) will reuse the same filename if you create one and delete it and then create another one. So while QTemporaryFile does guarantee that the filename is unique on the filesystem, it doesn't guarantee that the filename is unique on the filesystem *over time*.

    So, instead, I just keep the temp files around till I'm all done; at least this guarantees that I write to a different unique file so QPixmap doesn't assume it's in the cache. Not the best or elegant solution, but just the easiest way to get around it. I'd rather not have to roll my own QTemporaryFile.
    Last edited by gfunk; 10th August 2006 at 00:16.
    Software Engineer



  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPixmap caching?

    You can first create a new temp file and then delete the old one.

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  2. QPixmap -> HICON trouble.
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 15:51
  3. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16
  4. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24
  5. Text on QPixmap
    By Fabix in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 14:26

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.