我有一个简单的测试Qt应用程序,它试图在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];
}问题是NSUserNotificationCenter* center为空。我使用的是Qt 5.4.1,OS X 10.10。main函数如下所示:
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();
}我试着在鼠标点击的时候发送通知
MouseArea {
anchors.fill: parent
onClicked: app.notify("Hello", "World")
}有没有人知道为什么它不工作?
发布于 2015-04-03 16:43:50
我终于找到了问题所在。我的Info.plist文件缺少CFBundleIdentifier。添加之后,应用程序就可以在通知中心注册了。
<key>CFBundleIdentifier</key>
<string>org.notifytestosx.app</string>https://stackoverflow.com/questions/29341643
复制相似问题