From db9abc72ef6e374257e00c9553104584b973458a Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 24 Sep 2013 20:00:41 +0200 Subject: QMacNativeWidget: Have example use a delegate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This would be the case in most if not all the real life use cases. Change-Id: Ib7ebc6dbe471ce50f4bd1df9becba8e9806008e7 Reviewed-by: Morten Johan Sørvig --- examples/widgets/mac/qmacnativewidget/main.mm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/widgets/mac/qmacnativewidget/main.mm b/examples/widgets/mac/qmacnativewidget/main.mm index 28cf2adc3b..4558143b75 100644 --- a/examples/widgets/mac/qmacnativewidget/main.mm +++ b/examples/widgets/mac/qmacnativewidget/main.mm @@ -79,12 +79,14 @@ char **qtArgv; QApplication *qtApp = 0; } -@interface WindowCreator : NSObject {} -- (void)createWindow; +@interface WindowCreator : NSObject @end @implementation WindowCreator -- (void)createWindow { + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + Q_UNUSED(notification) // Qt widgets rely on a QApplication being alive somewhere qtApp = new QApplication(qtArgc, qtArgv); @@ -120,18 +122,25 @@ QApplication *qtApp = 0; // Show the NSWindow [window makeKeyAndOrderFront:NSApp]; } + +- (void)applicationWillTerminate:(NSNotification *)notification +{ + Q_UNUSED(notification) + + delete qtApp; +} + @end int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + Q_UNUSED(pool); - // Normally, we would use the application delegate. - // We resort to the notification mechanism for conciseness. + // Normally, we would use let the main bundle instanciate and set + // the application delegate, but we set it manually for conciseness. WindowCreator *windowCreator= [WindowCreator alloc]; - [[NSNotificationCenter defaultCenter] - addObserver:windowCreator selector:@selector(createWindow) - name:NSApplicationDidFinishLaunchingNotification object:nil]; + [[NSApplication sharedApplication] setDelegate:windowCreator]; // Save these for QApplication qtArgc = argc; -- cgit v1.2.3