diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index 081af380745..4abbcd5e655 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -62,7 +62,7 @@ public: QAtomicInt ref; QPalette::ResolveMask resolveMask = {0}; static inline int qt_palette_private_count = 0; - const int detach_no = ++qt_palette_private_count; + int detach_no = ++qt_palette_private_count; QExplicitlySharedDataPointer data; }; @@ -864,6 +864,8 @@ void QPalette::detach() if (!d->ref.deref()) delete d; d = x; + } else { + d->detach_no = ++QPalettePrivate::qt_palette_private_count; } } diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index 2e9a484b8b2..897511300b2 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -274,6 +274,14 @@ void tst_QPalette::cacheKey() const auto defaultSerNo = defaultCacheKey >> 32; const auto defaultDetachNo = defaultCacheKey & 0xffffffff; + QPalette changeTwicePalette(defaultPalette); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::red); + const auto firstChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, defaultCacheKey); + changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::green); + const auto secondChangeCacheKey = changeTwicePalette.cacheKey(); + QCOMPARE_NE(firstChangeCacheKey, secondChangeCacheKey); + QPalette copyDifferentData(defaultPalette); QPalette copyDifferentMask(defaultPalette); QPalette copyDifferentMaskAndData(defaultPalette);