[SOLVED] NSUserNotificationCenter defaultUserNotificationCenter returns null in Qt application
-
I have a simple test Qt application which tries to send user notification on OS X:
void Mac::notify(QString title, QString message) { NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease]; userNotification.title = title.toNSString(); userNotification.informativeText = message.toNSString(); NSUserNotificationCenter* center = [NSUserNotificationCenter defaultUserNotificationCenter]; [center deliverNotification:userNotification]; }
The problem is NSUserNotificationCenter* center being null. I am using Qt 5.4.1, OS X 10.10. main function looks like this:
int main(int argc, char** argv) { QApplication a(argc, argv); App app; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("app", &app); engine.load(QUrl("qrc:/Main.qml")); return a.exec(); }
And I try to send notification on a mouse click
MouseArea { anchors.fill: parent onClicked: app.notify("Hello", "World") }
I uploaded full project on github https://github.com/beemaster/osxnotifytest
Does anyone have an idea why it doesn't work? -
- you can get the answer in http://www.tanhao.me/pieces/517.html/
-
-
Finally I found the problem. My Info.plist file was missing CFBundleIdentifier. After I added it, application was able to register in Notification Center.
<key>CFBundleIdentifier</key> <string>org.notifytestosx.app</string>
This commit has required fix:
https://github.com/beemaster/osxnotifytest/commit/fa4154eebf9ffa51f9f9e5de5d12239c18d02370