From 8ea51f8aaa426fa14393b83082f9eec076d7d72a Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Thu, 21 Jul 2016 18:03:27 -0700 Subject: Make QCocoaMenuLoader a singleton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some auto-tests, we create several instances of QGuiApplication (though seldom, if ever, simultaneously). However, the QCocoaMenuLoader instance was never properly deallocated, resulting in NSApplication.servicesMenu to still be assigned. This resulted in an exception being raised (NSInternalInconsistencyException) the second time we would construct a QCocoaMenuLoader. The CPU cycles saving solution is to make QCocoaMenuLoader a singleton. This approach is also safe since this class' initialization doesn't depend on any state in QGuiApplication (even the application name is fetched from either the main bundle or the app's args). This also allows us to clean up some code in QCocoaApplication and QCocoaApplicationDelegate who have suffered from lack of attention over the years. Change-Id: Ic4c859d628ab8abd9b469b99c64293582f8e363d Reviewed-by: Morten Johan Sørvig Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm') diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index d18df35b80..d32a6fede4 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -122,7 +122,6 @@ QT_END_NAMESPACE { sharedCocoaApplicationDelegate = nil; [dockMenu release]; - [qtMenuLoader release]; if (reflectionDelegate) { [[NSApplication sharedApplication] setDelegate:reflectionDelegate]; [reflectionDelegate release]; @@ -171,14 +170,13 @@ QT_END_NAMESPACE - (void)setMenuLoader:(QCocoaMenuLoader *)menuLoader { - [menuLoader retain]; - [qtMenuLoader release]; - qtMenuLoader = menuLoader; + Q_UNUSED(menuLoader); + qWarning("-[QCocoaApplicationDelegate setMenuLoader:] is deprecated and is currently a no-op."); } - (QCocoaMenuLoader *)menuLoader { - return [[qtMenuLoader retain] autorelease]; + return [QT_MANGLE_NAMESPACE(QCocoaMenuLoader) sharedMenuLoader]; } - (BOOL) canQuit @@ -450,7 +448,7 @@ QT_END_NAMESPACE - (void)qtDispatcherToQAction:(id)sender { Q_UNUSED(sender); - [qtMenuLoader qtDispatcherToQPAMenuItem:sender]; + [[self menuLoader] qtDispatcherToQPAMenuItem:sender]; } @end -- cgit v1.2.3