From f7e9e035fd379ae4ad8cf2771e5ceca3e7602286 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sun, 18 Oct 2015 00:11:49 +0200 Subject: [PATCH] Fix cocoa plugin build with OS X 10.8 SDK With the 10.8 SDK, NSArray may not respond to firstObject which ends the build with an error. This implementation doesn't use it and also handles the case where no screen is available when calling qt_mac_mainScreenHeight Change-Id: Idce278423c37cc24d8fc31062a386e78d6487492 Reviewed-by: Jake Petroules --- src/plugins/platforms/cocoa/qcocoahelpers.mm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 8ad80333f8..f51c21ee9b 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -634,10 +634,14 @@ QString qt_mac_applicationName() int qt_mac_mainScreenHeight() { QMacAutoReleasePool pool; - // The first screen in the screens array is documented - // to have the (0,0) origin. - NSRect screenFrame = [[[NSScreen screens] firstObject] frame]; - return screenFrame.size.height; + NSArray *screens = [NSScreen screens]; + if ([screens count] > 0) { + // The first screen in the screens array is documented + // to have the (0,0) origin. + NSRect screenFrame = [[screens objectAtIndex: 0] frame]; + return screenFrame.size.height; + } + return 0; } int qt_mac_flipYCoordinate(int y)