Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Converting NSNotificationCenter events to Signals
Qt 6.11 is out! See what's new in the release blog

Converting NSNotificationCenter events to Signals

Scheduled Pinned Locked Moved Solved Mobile and Embedded
ios
11 Posts 2 Posters 5.7k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by
    #1

    I am integrating a third-party framework which implements events via the NSNotificationCenter. The framework is written in Objective-C. I was thinking I needed a way to capture to capture the events and convert them to signals that can be picked up by my iOS application, which is written in C++. Is that correct, or is there a more direct way to do it?

    I created a wrapper around the Objective-C framework calls which allow me to interface via C++, but the wrapper does not derive from QObject, so I can't emit signals directly (.h/.mm combo). Can I register for the notification events within my C++ code?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DRoscoe
      wrote on last edited by
      #2

      To provide a little more context, I would like a specific class in my main application to receive NSNotificationCenter events from the third-party framework. This class will handle the event and emit the necessary signals as defined in my abstract base class interface, to the main application.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Why not make the wrapper a QObject ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        D 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Why not make the wrapper a QObject ?

          D Offline
          D Offline
          DRoscoe
          wrote on last edited by
          #4

          @SGaist I actually did do that in the end. I am still left with the problem of registering my handlers for NSNotificationCenter events. I am having trouble defining "self". I do not know how to define "Self" as an instance of my class. I found an example in Git:
          platformios.mm
          But I don't want to be dealing with application level events, only events generated by my third party library.

          Do I have to define a delegate?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DRoscoe
            wrote on last edited by DRoscoe
            #5

            I believe I have solved my problem. I haven't tested it yet since the first call to the third-party library throws an exception. I am, however able to register my notification handler and confirm that its being executed

            @interface EventDelegate : NSObject //UIResponder
            {
              UtasCommunicationHandler* m_comm_handler;
            }
            @end
            
            @implementation EventDelegate
            - (id) initWithObject:(UtasCommunicationHandler*) comm_handler
            {
              self = [super init];
              if (self)
              {
                m_comm_handler = comm_handler;
            
                [[NSNotificationCenter defaultCenter]
                          addObserver:self
                          selector:@selector(updateConnectedTIMList:)
                          name:kUTCTIMNotificationUpdateConnectedTIMList
                          object:nil];
              }
              return self;
            }
            
            -(void)updateConnectedTIMList:(NSNotification*)notification
            {
                DNA_INFO("RECEIVED TIM CONNECTION")
            }
            
            @end
            
            1 Reply Last reply
            0
            • D Offline
              D Offline
              DRoscoe
              wrote on last edited by
              #6

              I solved the exception and have confirmed that I am receiving and handling NSNotificationCenter events in my Object-derived class.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Great !

                What was the problem ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                0
                • SGaistS SGaist

                  Great !

                  What was the problem ?

                  D Offline
                  D Offline
                  DRoscoe
                  wrote on last edited by
                  #8

                  @SGaist The handler I defined for the sample event was misspelled in the implementation. Once I corrected it, the events worked fine. I added three more after that and they all worked

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    So you got something like "unrecognized selector"

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    D 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      So you got something like "unrecognized selector"

                      D Offline
                      D Offline
                      DRoscoe
                      wrote on last edited by
                      #10

                      @SGaist Actually no. The compiler never complained. It just caused an unhandled exception to be thrown, which appeared to be caused by the call which set up the notification. If I had looked at the exception details, I might have seen the message you suggested, but I noticed the error, fixed it and the problem went away.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        The important point is that you could solve it :)

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

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