[Interest] QPixmapCache Simple Usage Fails

Durango durango.list at gmail.com
Sun May 18 22:22:40 CEST 2014

I’m having some difficulty with getting QPixmapCache to work for me. In my case I read images in a proprietary format, convert to QPixmap, then insert into the cache. When I later get a cache hit and retrieve the QPixmap, I get a damaged image, although of the right size and pixel format.

The image damage is what I would expect if the pixmap was pointing to free memory. But QPixmapCache::insert is supposed to make a copy of the pixels, right?

The code is very simple so I assume I’m overlooking something obvious. This is with Qt 5.2.1.

static bool getProxyImageCached(const QString &path, int targetSizeWidth, int targetSizeHeight, QPixmap &pm, void *imageProcSettings);

bool SAImageIO::getProxyImageCached(const QString &path, int targetSizeWidth, int targetSizeHeight, QPixmap &pm)
    bool returnVal = false;

    if (!(returnVal = QPixmapCache::find(path, pm))) {
        if ((returnVal = proxyImageFromFile(path, targetSizeWidth, targetSizeHeight, pm))) {
            QPixmapCache::insert(path, pm); //comment this out and images are OK

If I comment out the QPixmapCache::insert() call then all works as expected, albeit slowly. To me this shows that the corruption is in the cache and not in my proxy image processing code.

Anyone have a suggestion for where I’m going wrong?

— Matt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140518/6e8089fa/attachment.html>

More information about the Interest mailing list