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. Using QCocoaNativeContext
Forum Updated to NodeBB v4.3 + New Features

Using QCocoaNativeContext

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 638 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.
  • G Offline
    G Offline
    glennr
    wrote on last edited by
    #1

    I'm wanting to get the native OpenGL context on macOS but when including
    <QtPlatformHeaders/QCocoaNativeContext> I get the following error:

    In file included from
    .../qt-5.12.7/qtbase/include/QtPlatformHeaders/QCocoaNativeContext:1:
    .../qt-5.12.7/qtbase/include/QtPlatformHeaders/qcocoanativecontext.h:1:
    In file included from
    .../qt-5.12.7/qtbase/include/QtPlatformHeaders/../../src/platformheaders/nativecontexts/qcocoanativecontext.h:44:
    In file included from
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSOpenGL.h:8:
    In file included from
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/AppKit.framework/Headers/AppKitDefines.h:11:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1:
    error: expected unqualified-id
    @class NSString, Protocol;

    Looks like it's including Objective-C stuff that the compiler doesn't like.

    This is in a Xcode (11.3) project that was created by CMake.

    How do I make this work?

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

      Hi,

      You are going to use Objective-C code, therefore you need to change your file extension to .mm so that the compiler treats it as Objective-C++ code. Then you'll be able to compile it.

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

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You are going to use Objective-C code, therefore you need to change your file extension to .mm so that the compiler treats it as Objective-C++ code. Then you'll be able to compile it.

        G Offline
        G Offline
        glennr
        wrote on last edited by
        #3

        @SGaist said in Using QCocoaNativeContext:

        Hi,

        You are going to use Objective-C code, therefore you need to change your file extension to .mm so that the compiler treats it as Objective-C++ code. Then you'll be able to compile it.

        I created a myfile.m with #include <QtPlatformHeaders/QCocoaNativeContext> and added that to my project.

        Now I get a compilation error: Qt requires C++11 support

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

          Not .m but .mm

          There's a difference between the two. One is for Objective-C and the other for Objective-C++. You want the second one.

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

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            Not .m but .mm

            There's a difference between the two. One is for Objective-C and the other for Objective-C++. You want the second one.

            G Offline
            G Offline
            glennr
            wrote on last edited by
            #5

            @SGaist Thanks. Changed to .mm and it compiles now.

            I didn't find this information in any of the Qt documentation. Do you know if it is in there somewhere? If not I'll submit a bug report.

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

              Well, when you want to use native API's like that, you are expected to have that kind of knowledge.

              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
              1
              • G glennr

                @SGaist Thanks. Changed to .mm and it compiles now.

                I didn't find this information in any of the Qt documentation. Do you know if it is in there somewhere? If not I'll submit a bug report.

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @glennr said in Using QCocoaNativeContext:

                I didn't find this information in any of the Qt documentation.

                There is also no information that a file ending with 'c' is treated as c and 'cpp' as c++ - it's basic knowledge when you want to use a language.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                G 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @glennr said in Using QCocoaNativeContext:

                  I didn't find this information in any of the Qt documentation.

                  There is also no information that a file ending with 'c' is treated as c and 'cpp' as c++ - it's basic knowledge when you want to use a language.

                  G Offline
                  G Offline
                  glennr
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher said in Using QCocoaNativeContext:

                  @glennr said in Using QCocoaNativeContext:

                  I didn't find this information in any of the Qt documentation.

                  There is also no information that a file ending with 'c' is treated as c and 'cpp' as c++ - it's basic knowledge when you want to use a language.

                  I wasn't meaning the .m/.mm part. I was referring to the fact that the QtPlatformHeaders/QCocoaNativeContext header can only be included in a .mm file.

                  Qt is a cross platform C++ framework and presumably its users (who are C++ developers and not necessarily platform experts) expect some sort of insulation from platform issues. In this case it is unavoidable so it would be a courtesy to those non-mac developers to mention in the documentation for QCocoaNativeContext that it is not C++ and can only be included in an Objective-C++ file.

                  My specific use case for this is that I need a pointer to the OpenGLContext to pass to a third party library. I don't need to access any of the Objective-C++ APIs in my code.

                  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