diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-05-29 16:36:09 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2019-05-29 17:11:40 +0200 |
commit | b53994de5f1b641ca2f6c79048339ff34fe14b55 (patch) | |
tree | 4c6c1fe9cc8ff91a8ac563d06cfbb1edcd5218e7 /src/plugins/platforms | |
parent | 15d73a9f479e88af85944119e79d88ed26d4f346 (diff) |
macOS: Use QMacNotificationObserver over manual notification handling
This also fixes a bug where we were implicitly capturing this inside
the block, which meant that we would crash if the theme was recreated.
The capture is now tied to the lifetime of QCocoaTheme.
Change-Id: I37df8e6c0b33bf41e76d66be3cf29576041a7546
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoatheme.mm | 6 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index c42fa7d2e8..63227ed6c1 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -45,6 +45,8 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaThemeAppAppearanceObserver)); +#include <QtCore/private/qcore_mac_p.h> + QT_BEGIN_NAMESPACE class QPalette; @@ -82,6 +84,7 @@ public: private: mutable QPalette *m_systemPalette; + QMacNotificationObserver m_systemColorObserver; mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes; mutable QHash<QPlatformTheme::Font, QFont*> m_fonts; QT_MANGLE_NAMESPACE(QCocoaThemeAppAppearanceObserver) *m_appearanceObserver; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index efe670abed..ba93560689 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -133,10 +133,10 @@ QCocoaTheme::QCocoaTheme() m_appearanceObserver = [[QCocoaThemeAppAppearanceObserver alloc] initWithTheme:this]; #endif - [[NSNotificationCenter defaultCenter] addObserverForName:NSSystemColorsDidChangeNotification - object:nil queue:nil usingBlock:^(NSNotification *) { + m_systemColorObserver = QMacNotificationObserver(nil, + NSSystemColorsDidChangeNotification, [this] { handleSystemThemeChange(); - }]; + }); } QCocoaTheme::~QCocoaTheme() |