Fixed QPixmapCache associating path with wrong QPixmap.

QPixmap::load() would not detach, so multiple paths could get associated
with the same QPixmap, causing the wrong pixmap to be shown.

Task-number: QTBUG-29639
Change-Id: I064dd6a9611b5996853bec9fb20b6224a0adcf62
Reviewed-by: aavit <eirik.aavitsland@digia.com>
This commit is contained in:
Samuel Rødal 2013-02-12 12:58:08 +01:00 committed by The Qt Project
parent f5acd545a8
commit 62d25e4d4f
2 changed files with 17 additions and 0 deletions

View File

@ -760,6 +760,8 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
return false;
}
detach();
QFileInfo info(fileName);
QString key = QLatin1String("qt_pixmap")
% info.absoluteFilePath()

View File

@ -166,6 +166,7 @@ private slots:
void loadAsBitmapOrPixmap();
void scaled_QTBUG19157();
void detachOnLoad_QTBUG29639();
};
static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
@ -1488,5 +1489,19 @@ void tst_QPixmap::scaled_QTBUG19157()
QVERIFY(!foo.isNull());
}
void tst_QPixmap::detachOnLoad_QTBUG29639()
{
const QString prefix = QFINDTESTDATA("convertFromImage");
QPixmap a;
a.load(prefix + "/task31722_0/img1.png");
a.load(prefix + "/task31722_0/img2.png");
QPixmap b;
b.load(prefix + "/task31722_0/img1.png");
QVERIFY(a.toImage() != b.toImage());
}
QTEST_MAIN(tst_QPixmap)
#include "tst_qpixmap.moc"