You can easily integrate Qt/C++ code with Cocoa/Objective-C. XCode supports Objective-C++ which is a mix of C++ and Objective-C. These files will have a .mm extension and are added to your QMake project using the OBJECTIVE_SOURCES
variable (which is unfortunately not in the official QMake documentation). So just add the NSUserNotification
code right into a C++ class.
QMake Project File
HEADERS += Foo.h
OBJECTIVE_SOURCES += Foo.mm
LIBS += -framework Foundation
INCLUDEPATH += /System/Library/Frameworks/Foundation.framework/Versions/C/Headers
Foo.h
#ifndef FOO_H
#define FOO_H
class Foo {
public:
void test();
};
#endif
Foo.mm
#include "foo.h"
#include <NSUserNotification.h>
void Foo::test() {
NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
userNotification.title = @"My Great Title";
userNotification.informativeText = @"Blah Blah Blah";
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification];
}