【问题标题】:NSUserNotificationCenter defaultUserNotificationCenter returns null in Qt applicationNSUserNotificationCenter defaultUserNotificationCenter 在 Qt 应用程序中返回 null
【发布时间】:2015-06-03 04:46:27
【问题描述】:

我有一个简单的测试 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。主函数如下所示:

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")
}

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

【问题讨论】:

    标签: c++ macos qt nsusernotification


    【解决方案1】:

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

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

    【讨论】:

    • 提交是死链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 1970-01-01
    相关资源
    最近更新 更多