path: root/src
diff options
authorVolker Hilsheimer <>2019-07-12 12:22:30 +0200
committerVolker Hilsheimer <>2019-07-18 15:26:49 +0200
commitde775f2e62157a6d572b4c363bee48b84d3be630 (patch)
tree6b54043f966e9a310f29d2746f21738cc08309d3 /src
parent907923b7cafad8cff6f0f5c8764e9181ac1531bd (diff)
macOS: activate correct object when using multiple QSystemTrayIcons
Since we need to set the delegate on the defaultUserNotificationCenter, which is a gobal object, we have to update the delegate when we show the message. Otherwise, the last delegate created and set will receive the notification, and the last QSystemTrayIcon created will emit the activated signal. Before clearing the delegate upon destruction, make sure that it's the right item first. Also updating coding style in the respective parts of the code, and plugging a memory leak. Change-Id: Ife62ae0776a5a610a6fd735b2959b807c3a410c7 Fixes: QTBUG-77003 Reviewed-by: Tor Arne Vestbø <>
Diffstat (limited to 'src')
1 files changed, 8 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/ b/src/plugins/platforms/cocoa/
index 16543bfb8c..597cfa8318 100644
--- a/src/plugins/platforms/cocoa/
+++ b/src/plugins/platforms/cocoa/
@@ -118,11 +118,13 @@ class QSystemTrayIconSys
QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) {
item = [[QNSStatusItem alloc] initWithSysTray:sys];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item];
+ NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item;
~QSystemTrayIconSys() {
[[[item item] view] setHidden: YES];
- [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:nil];
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ if (center.delegate == item)
+ center.delegate = nil;
[item release];
QNSStatusItem *item;
@@ -277,7 +279,10 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
notification.contentImage = [nsimage autorelease];
- [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
+ NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter;
+ center.delegate = m_sys->item;
+ [center deliverNotification:notification];
+ [notification release];