diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2013-04-02 17:08:59 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-03 18:03:26 +0200 |
commit | 680d8aa6c5240715d9f425f1d0a018ebb192bb43 (patch) | |
tree | 164528b9afb4800febbd5e0f0199539ad57ce05f | |
parent | 8b99445755bac9c1bc1c2ce84a6e21edadca1f11 (diff) |
QPA/Mac: Fix resources leaking
Having static QFont instance leads to a resources leaking, since QFontCache
is unable to clean-up font engines when the application exits.
Relates to QTBUG-25434
Change-Id: I71d91094de27c07ab2434c415e4c28b6acab3646
Reviewed-by: David Faure (KDE) <faure@kde.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.mm | 2 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiostheme.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/ios/qiostheme.mm | 14 |
3 files changed, 13 insertions, 7 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index beaa50da6d..f8eed0ebf1 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -74,6 +74,8 @@ QCocoaTheme::QCocoaTheme() QCocoaTheme::~QCocoaTheme() { delete m_systemPalette; + qDeleteAll(m_palettes); + qDeleteAll(m_fonts); } bool QCocoaTheme::usePlatformNativeDialog(DialogType dialogType) const diff --git a/src/plugins/platforms/ios/qiostheme.h b/src/plugins/platforms/ios/qiostheme.h index 5ccbcac710..b03f65f556 100644 --- a/src/plugins/platforms/ios/qiostheme.h +++ b/src/plugins/platforms/ios/qiostheme.h @@ -42,6 +42,7 @@ #ifndef QIOSTHEME_H #define QIOSTHEME_H +#include <QtCore/QHash> #include <qpa/qplatformtheme.h> QT_BEGIN_NAMESPACE @@ -57,6 +58,9 @@ public: const QFont *font(Font type = SystemFont) const; static const char *name; + +private: + mutable QHash<QPlatformTheme::Font, QFont *> m_fonts; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiostheme.mm b/src/plugins/platforms/ios/qiostheme.mm index f98781f8a7..e7093185aa 100644 --- a/src/plugins/platforms/ios/qiostheme.mm +++ b/src/plugins/platforms/ios/qiostheme.mm @@ -59,6 +59,7 @@ QIOSTheme::QIOSTheme() QIOSTheme::~QIOSTheme() { + qDeleteAll(m_fonts); } QVariant QIOSTheme::themeHint(ThemeHint hint) const @@ -73,8 +74,7 @@ QVariant QIOSTheme::themeHint(ThemeHint hint) const const QFont *QIOSTheme::font(Font type) const { - static QHash<QPlatformTheme::Font, QFont *> fonts; - if (fonts.isEmpty()) { + if (m_fonts.isEmpty()) { // The real system font on iOS is '.Helvetica Neue UI', as returned by both [UIFont systemFontOfSize] // and CTFontCreateUIFontForLanguage(kCTFontSystemFontType, ...), but this font is not included when // populating the available fonts in QCoreTextFontDatabase::populateFontDatabase(), since the font @@ -84,13 +84,13 @@ const QFont *QIOSTheme::font(Font type) const // For now we hard-code the font to Helvetica, which should be very close to the actual // system font. QLatin1String systemFontFamilyName("Helvetica"); - fonts.insert(QPlatformTheme::SystemFont, new QFont(systemFontFamilyName, [UIFont systemFontSize])); - fonts.insert(QPlatformTheme::SmallFont, new QFont(systemFontFamilyName, [UIFont smallSystemFontSize])); - fonts.insert(QPlatformTheme::LabelFont, new QFont(systemFontFamilyName, [UIFont labelFontSize])); - fonts.insert(QPlatformTheme::PushButtonFont, new QFont(systemFontFamilyName, [UIFont buttonFontSize])); + m_fonts.insert(QPlatformTheme::SystemFont, new QFont(systemFontFamilyName, [UIFont systemFontSize])); + m_fonts.insert(QPlatformTheme::SmallFont, new QFont(systemFontFamilyName, [UIFont smallSystemFontSize])); + m_fonts.insert(QPlatformTheme::LabelFont, new QFont(systemFontFamilyName, [UIFont labelFontSize])); + m_fonts.insert(QPlatformTheme::PushButtonFont, new QFont(systemFontFamilyName, [UIFont buttonFontSize])); } - return fonts.value(type, 0); + return m_fonts.value(type, 0); } QT_END_NAMESPACE |