From d7bcdc3a442b99c2caebd4cfd38de67e14090e05 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 2 Nov 2016 16:45:41 +0100 Subject: QStyleHelper::uniqueName(): Improve palette pixmap cache key Use QDataStream to obtain cache key for a palettes that are different from the default QPalette. This results in unique keys for palettes created from QStyleSheetStyle's render rules. Task-number: QTBUG-56743 Change-Id: Icbfe165f705ef3e1c9e88cfc9dca88ff1d1e81e6 Reviewed-by: Andy Shaw --- src/widgets/styles/qstylehelper.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 6602b58a9d..960695e9df 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -43,6 +43,8 @@ #include "qstylehelper_p.h" #include +#include +#include QT_BEGIN_NAMESPACE @@ -56,7 +58,6 @@ QString uniqueName(const QString &key, const QStyleOption *option, const QSize & QString tmp = key % HexString(option->state) % HexString(option->direction) % HexString(complexOption ? uint(complexOption->activeSubControls) : 0u) - % HexString(option->palette.cacheKey()) % HexString(size.width()) % HexString(size.height()); @@ -67,6 +68,25 @@ QString uniqueName(const QString &key, const QStyleOption *option, const QSize & % QLatin1Char(spinBox->frame ? '1' : '0'); ; } #endif // QT_NO_SPINBOX + + // QTBUG-56743, try to create a palette cache key reflecting the value, + // as leaks may occur in conjunction with QStyleSheetStyle/QRenderRule modifying + // palettes when using QPalette::cacheKey() + if (option->palette != QGuiApplication::palette()) { + tmp.append(QLatin1Char('P')); +#ifndef QT_NO_DATASTREAM + QByteArray key; + key.reserve(5120); // Observed 5040B for a serialized palette on 64bit + { + QDataStream str(&key, QIODevice::WriteOnly); + str << option->palette; + } + const QByteArray sha1 = QCryptographicHash::hash(key, QCryptographicHash::Sha1).toHex(); + tmp.append(QString::fromLatin1(sha1)); +#else // QT_NO_DATASTREAM + tmp.append(QString::number(option->palette.cacheKey(), 16)); +#endif // !QT_NO_DATASTREAM + } return tmp; } -- cgit v1.2.3