From 78a0cf9c347b80e7d7b1eb369d8ff28c49ed1b7d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 21 Apr 2010 09:29:15 +0200 Subject: QStyleSheetStyle: fix memory leak on base style change On every change of the base style it is inserted into styleSheetCache. If the base style gets destroyed, it must be removed from the cache. Task-number: QTBUG-4074 Reviewed-by: ogoffart --- src/gui/styles/qstylesheetstyle.cpp | 9 ++++++++- src/gui/styles/qstylesheetstyle_p.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index 285a789..0b615bc 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1533,7 +1533,9 @@ QVector QStyleSheetStyle::styleRules(const QWidget *w) const QHash::const_iterator defaultCacheIt = styleSheetCache->constFind(baseStyle()); if (defaultCacheIt == styleSheetCache->constEnd()) { defaultSs = getDefaultStyleSheet(); - styleSheetCache->insert(baseStyle(), defaultSs); + QStyle *bs = baseStyle(); + styleSheetCache->insert(bs, defaultSs); + QObject::connect(bs, SIGNAL(destroyed(QObject*)), this, SLOT(styleDestroyed(QObject*)), Qt::UniqueConnection); } else { defaultSs = defaultCacheIt.value(); } @@ -2660,6 +2662,11 @@ void QStyleSheetStyle::widgetDestroyed(QObject *o) autoFillDisabledWidgets->remove((const QWidget *)o); } +void QStyleSheetStyle::styleDestroyed(QObject *o) +{ + styleSheetCache->remove(o); +} + /*! * Make sure that the cache will be clean by connecting destroyed if needed. * return false if the widget is not stylable; diff --git a/src/gui/styles/qstylesheetstyle_p.h b/src/gui/styles/qstylesheetstyle_p.h index 50abef9..fd81437 100644 --- a/src/gui/styles/qstylesheetstyle_p.h +++ b/src/gui/styles/qstylesheetstyle_p.h @@ -147,6 +147,7 @@ protected: private Q_SLOTS: void widgetDestroyed(QObject *); + void styleDestroyed(QObject *); private: int refcount; -- cgit v0.12