From f552dc200d857505df500b3ce0b99d5f7c74c951 Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Tue, 26 May 2009 13:26:14 +0200 Subject: We first remove the pixmap from the cache and then release the key If we don't remove the pixmap from QCache first then the key is invalid and the removal failed Reviewed-by: sroedal --- src/gui/image/qpixmapcache.cpp | 4 +++- tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 3cfc191..82b42b4 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -342,8 +342,10 @@ bool QPMCache::remove(const QString &key) bool QPMCache::remove(const QPixmapCache::Key &key) { + bool result = QCache::remove(key); + //We release the key after we removed it from the cache releaseKey(key); - return QCache::remove(key); + return result; } void QPMCache::resizeKeyArray(int size) diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index 405ac34..fb5998a 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -369,6 +369,14 @@ void tst_QPixmapCache::remove() key = QPixmapCache::insert(p1); QCOMPARE(getPrivate(key)->key, 1); + //Test if pixmaps are correctly deleted + QPixmapCache::clear(); + key = QPixmapCache::insert(p1); + QCOMPARE(getPrivate(key)->key, 1); + QVERIFY(QPixmapCache::find(key, &p1) != 0); + QPixmapCache::remove(key); + QCOMPARE(p1.isDetached(), true); + //We mix both part of the API QPixmapCache::clear(); p1.fill(Qt::red); -- cgit v0.12