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] Library using Qt 5 with namespace in application using Qt 4 or Qt 5.
Forum Update on Monday, May 27th 2025

[Solved] Library using Qt 5 with namespace in application using Qt 4 or Qt 5.

Scheduled Pinned Locked Moved General and Desktop
mac os xqapplication
9 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    Melanie
    wrote on last edited by Melanie
    #1

    Qt 5.3 on Mac OS X (Mavericks).
    I'm working on a library which shows UI using Qt. The Qt used by this library has its own namespace. This library creates its own QApplication, otherwise, it can't show QWidgets.

    If this library is used in an application which handles its own UI through [NSApp run], it works fine.

    However, if this library is used in an application which uses QApplication::exec in Qt 4.8 or Qt 5.3 without namespace, it doesn't. Panels are brought up, but no input events are handled. This is the case for both panels owned by the calling application and panels owned by the library. (Note: this setup works with Qt 4; a library using Qt 4.8 with namespace in an application which uses Qt 4.8 without namespace. )

    I know the QApplication documentation says any GUI application is supposed to have exactly one QApplication, but I don't have any control over what UI technology the calling application is using.

    Any suggestions on how to make this work would be greatly appreciated.

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

      Hi and welcome to devnet,

      Just to be sure I understand you correctly: are you trying to run an application which should load two different libraries, one built with Qt 4 and one with Qt 5 ?

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Just to be sure I understand you correctly: are you trying to run an application which should load two different libraries, one built with Qt 4 and one with Qt 5 ?

        M Offline
        M Offline
        Melanie
        wrote on last edited by
        #3

        @SGaist
        Hi and thank you,

        not exactly. The application is using Qt 5 without namespace, or Qt 4, or any other framework, and the library which uses Qt 5 with a namespace. So the appliction as a whole will end up loading its own Qt 4/Qt 5/..., one instance of 'my' library and the Qt 5 with namespace that comes with 'my' library.

        (Note: At the moment, I'm investigating if this patch may help.)

        1 Reply Last reply
        0
        • M Melanie

          Qt 5.3 on Mac OS X (Mavericks).
          I'm working on a library which shows UI using Qt. The Qt used by this library has its own namespace. This library creates its own QApplication, otherwise, it can't show QWidgets.

          If this library is used in an application which handles its own UI through [NSApp run], it works fine.

          However, if this library is used in an application which uses QApplication::exec in Qt 4.8 or Qt 5.3 without namespace, it doesn't. Panels are brought up, but no input events are handled. This is the case for both panels owned by the calling application and panels owned by the library. (Note: this setup works with Qt 4; a library using Qt 4.8 with namespace in an application which uses Qt 4.8 without namespace. )

          I know the QApplication documentation says any GUI application is supposed to have exactly one QApplication, but I don't have any control over what UI technology the calling application is using.

          Any suggestions on how to make this work would be greatly appreciated.

          M Offline
          M Offline
          Melanie
          wrote on last edited by
          #4

          I've marked this as solved.

          The reason why it doesn't work in Qt 5 are a number of missing Objective-C namespace prefixes in qcocoaapplication.mm that used to be present in Qt 4.8.

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

            Can you point the problematic parts ?

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

            M 1 Reply Last reply
            0
            • SGaistS SGaist

              Can you point the problematic parts ?

              M Offline
              M Offline
              Melanie
              wrote on last edited by Melanie
              #6

              @SGaist

              I'm not an Objective C developer, so I'm probably interpreting some things wrongly, but this is what I see happening:

              The calling application sets a QNSApplication as NSApp as part of the creation of a QGUIApplication. This QNSApplication doesn't have a namespace.

              The library which uses QT 5 with namespace creates a QGUIApplication as well. Part of this creation is calling qt_redirectNSApplicationSendEvent (qcocoaappliction.mm). if ([NSApp isMemberOfClass:[QNSApplication class]]) returns false (not sure why, as it is a QNSApplication), so it calls qt_cocoa_change_implementation (qcocoaintrospection) to use qt_sendEvent_replacement (no namespace) for sendEvent.
              When sendEvent is called with an event from the library, it's redirected to qt_sendEvent_replacement (no namespace), which redirects it to the original. This turns out to be qt_sendEvent_original (no namespace), which ignores signals.

              If the replacements are namespaced, the original handler is not qt_sendEvent_original, I suspect it's the real original of NSApplication instead.

              (I'll try to make a patch.)
              (Edit: it'll look very much like this one.)

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

                You should consider submitting to code review

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

                M 1 Reply Last reply
                0
                • SGaistS SGaist

                  You should consider submitting to code review

                  M Offline
                  M Offline
                  Melanie
                  wrote on last edited by
                  #8

                  @SGaist Yes, that's the plan. :)

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

                    Very good ! :)

                    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