PDA

View Full Version : QPixmap caching?



gfunk
8th August 2006, 21:46
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.

wysota
9th August 2006, 23:35
Could you provide a minimal compilable example which reproduces the problem?

gfunk
9th August 2006, 23:45
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.

wysota
11th August 2006, 22:46
You can first create a new temp file and then delete the old one.