From 62d25e4d4f02a53da25b9f14cc9e0244d6655312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 12 Feb 2013 12:58:08 +0100 Subject: [PATCH] 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 --- src/gui/image/qpixmap.cpp | 2 ++ tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 852025117b..b6a21f588e 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -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() diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 0e86a425f3..f5298a1690 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -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"