summaryrefslogtreecommitdiffstats
path: root/examples/widgets/mac
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-09-24 20:00:41 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-26 22:25:10 +0200
commitdb9abc72ef6e374257e00c9553104584b973458a (patch)
treef18fbbf55d10642fe60895d40d3b1c93229bbc8c /examples/widgets/mac
parent79561dd899e06f47b562914710d055a02b5f91fe (diff)
QMacNativeWidget: Have example use a delegate
This would be the case in most if not all the real life use cases. Change-Id: Ib7ebc6dbe471ce50f4bd1df9becba8e9806008e7 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'examples/widgets/mac')
-rw-r--r--examples/widgets/mac/qmacnativewidget/main.mm25
1 files changed, 17 insertions, 8 deletions
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 <NSApplicationDelegate>
@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;