gpt4 book ai didi

c++ - NSUserNotificationCenter defaultUserNotificationCenter在Qt应用程序中返回null

转载 作者:行者123 更新时间:2023-12-01 14:50:57 25 4
gpt4 key购买 nike

我有一个简单的测试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 *中心为空。我正在使用Qt 5.4.1,OS X 10.10。主要功能如下:
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")
}

有谁知道为什么它不起作用?

最佳答案

终于我找到了问题。我的Info.plist文件缺少CFBundleIdentifier。添加后,应用程序便可以在通知中心注册。

<key>CFBundleIdentifier</key>
<string>org.notifytestosx.app</string>

关于c++ - NSUserNotificationCenter defaultUserNotificationCenter在Qt应用程序中返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29341643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com