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. Is it possible to use ARC on Mac in a Qt application?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use ARC on Mac in a Qt application?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 548 Views 4 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I know in the past Qt was incompatible with ARC, is it still the case with Qt 6? Is there a way to enable ARC for my application without breaking Qt?

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

      Hi,

      Can you remind me what ARC is ? The name rings a really old distant bell.

      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
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        Automatic reference counting, a feature of Objective-C that is usually enabled and expected in macOS applications, but Qt is incompatible with it, or at least used to be.

        Pl45m4P 1 Reply Last reply
        0
        • V Violet Giraffe

          Automatic reference counting, a feature of Objective-C that is usually enabled and expected in macOS applications, but Qt is incompatible with it, or at least used to be.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @Violet-Giraffe said in Is it possible to use ARC on Mac in a Qt application?:

          Automatic reference counting

          I don't know what this is and never used Objective-C, but what about smart pointers, either the STL types in C++, like std::unique_ptr, std::shared_ptr and std::weak_ptr or the matching Qt counterparts (QPointer, QSharedPointer, QScopedPointer, QWeakPointer, ... )?


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          V 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @Violet-Giraffe said in Is it possible to use ARC on Mac in a Qt application?:

            Automatic reference counting

            I don't know what this is and never used Objective-C, but what about smart pointers, either the STL types in C++, like std::unique_ptr, std::shared_ptr and std::weak_ptr or the matching Qt counterparts (QPointer, QSharedPointer, QScopedPointer, QWeakPointer, ... )?

            V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by Violet Giraffe
            #5

            @Pl45m4, that is unrelated. Of course I know how to use smart pointers. Our Qt application has started having inexplicable issues calling macOS frameworks (system functions), which happens in a Qt application but not in a clean native Mac application. ARC is one notable way in which the Qt application differs from the native application. And in general, not being able to use ARC has been a major pain for the Mac version of our application, so I would love to finally enable it if possible.

            Pl45m4P 1 Reply Last reply
            0
            • V Violet Giraffe

              @Pl45m4, that is unrelated. Of course I know how to use smart pointers. Our Qt application has started having inexplicable issues calling macOS frameworks (system functions), which happens in a Qt application but not in a clean native Mac application. ARC is one notable way in which the Qt application differs from the native application. And in general, not being able to use ARC has been a major pain for the Mac version of our application, so I would love to finally enable it if possible.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @Violet-Giraffe

              Because Qt's platform independency, I doubt that there is something that specific (for adapted from one language and for mac only) in C++ or Qt.

              After reading this thread on StackOverflow, I now know what it does/is, but this reply there explains why it wasn't introduced to C++ or Qt yet.

              I'm not an expert when it comes to macOS, but if your C++ Qt app on Mac really needs this feature, it's probably a design issue with your app and there is also probably a better alternative/workaround for this (for memory management).

              Edit:
              I guess nothing has changed since then:
              (if it would have been added already, it would be documented somewhere, for sure)

              • https://wiki.qt.io/Apple_Platforms_Coding_Conventions

              Maybe someone who knows more than me or the Qt maintainers will comment on this :)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Violet Giraffe
                wrote on last edited by
                #7

                You're still missing the point, it's a trait of the application, ARC or no ARC. I don't need to use it, but I may need it to be enabled for other macOS stuff to function properly in this application. Yes, I've seen that article, but it's old.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  IgKh
                  wrote on last edited by
                  #8

                  ARC isn't actually a property of the application, or an all-or-nothing thing. It can be enabled or not for each compilation unit separately - just add -fobjc-arc to the compilation options of the relevant Objective-C++ .mm files. AFAIK Clang's Objective-C compiler's implementation of ARC doesn't do full-project analysis, but just relies on the selector naming conventions to deduce type of ownership. So whether Qt's Cocoa platform integration and style use ARC or MRC shouldn't matter.

                  That said, the problem with enabling ARC on Qt applications seems to be primarily that ARC forbids casting between pointers to Objective-C objects and C/C++ types. So something pretty common to do like casting the result of QWidget::winId to a NSView* is a compilation error under ARC:

                   error: cast of 'WId' (aka 'unsigned long long') to 'NSView *' is disallowed with ARC
                          NSView* view = reinterpret_cast<NSView*>(parent->winId());
                  
                  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