Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] NSUserNotificationCenter defaultUserNotificationCenter returns null in Qt application

    General and Desktop
    nsusernotificat defaultusernoti osx
    2
    6
    2825
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      beemaster last edited by beemaster

      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?

      1 Reply Last reply Reply Quote 0
      • TobyYi
        TobyYi last edited by

        I use your code,and it works well,my platform is mac osx 10.10.2,It can be show In local nofify

        将QtCoding进行到底,做Qt的宠儿
        关注移动互联网,关注手机助手
        开发即时通讯,服务于金融行业
        My github :https://github.com/toby20130333

        B 1 Reply Last reply Reply Quote 0
        • B
          beemaster @TobyYi last edited by

          @TobyYi that's surprising, can you post a screenshot, please

          TobyYi 1 Reply Last reply Reply Quote 0
          • TobyYi
            TobyYi last edited by

            • you can get the answer in http://www.tanhao.me/pieces/517.html/

            将QtCoding进行到底,做Qt的宠儿
            关注移动互联网,关注手机助手
            开发即时通讯,服务于金融行业
            My github :https://github.com/toby20130333

            1 Reply Last reply Reply Quote 0
            • TobyYi
              TobyYi @beemaster last edited by

              @beemaster screenshot in http://www.heilqt.com/topic/551e44bc50b5ec322fd1876a

              将QtCoding进行到底,做Qt的宠儿
              关注移动互联网,关注手机助手
              开发即时通讯,服务于金融行业
              My github :https://github.com/toby20130333

              1 Reply Last reply Reply Quote 0
              • B
                beemaster last edited by

                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

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post