Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] NSUserNotificationCenter defaultUserNotificationCenter returns null in Qt application
QtWS25 Last Chance

[SOLVED] NSUserNotificationCenter defaultUserNotificationCenter returns null in Qt application

Scheduled Pinned Locked Moved General and Desktop
nsusernotificatdefaultusernotiosx
6 Posts 2 Posters 3.2k Views
  • 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 Offline
    B Offline
    beemaster
    wrote on 2 Apr 2015, 10:38 last edited by beemaster 4 Mar 2015, 09:13
    #1

    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
    0
    • T Offline
      T Offline
      TobyYi
      wrote on 2 Apr 2015, 14:06 last edited by
      #2

      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 3 Apr 2015, 07:20
      0
      • T TobyYi
        2 Apr 2015, 14:06

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

        B Offline
        B Offline
        beemaster
        wrote on 3 Apr 2015, 07:20 last edited by
        #3

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

        T 1 Reply Last reply 3 Apr 2015, 07:44
        0
        • T Offline
          T Offline
          TobyYi
          wrote on 3 Apr 2015, 07:36 last edited by
          #4
          • 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
          0
          • B beemaster
            3 Apr 2015, 07:20

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

            T Offline
            T Offline
            TobyYi
            wrote on 3 Apr 2015, 07:44 last edited by
            #5

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

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

            1 Reply Last reply
            0
            • B Offline
              B Offline
              beemaster
              wrote on 3 Apr 2015, 09:12 last edited by
              #6

              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
              0

              5/6

              3 Apr 2015, 07:44

              • Login

              • Login or register to search.
              5 out of 6
              • First post
                5/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved