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. Qt does not recognize objective-c header files?
Forum Updated to NodeBB v4.3 + New Features

Qt does not recognize objective-c header files?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 709 Views 2 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.
  • S Offline
    S Offline
    senmx
    wrote on last edited by senmx
    #1

    Keywords like "@protocol" and "-(void)..." will prompt errors, but writing to the .m file is no problem.

    #import <Foundation/Foundation.h>
    #import <StoreKit/StoreKit.h>
    
    @protocol ToolDelegate <NSObject>
    
    -(void)ToolSysWrong;
    -(void)ToolGotProducts:(NSMutableArray *)products;
    ...
    
    1 Reply Last reply
    1
    • S senmx

      @SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @senmx said in Qt does not recognize objective-c header files?:

      @SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?

      No, pure Objective-C is written in .m files. If you want to mix Objective-C and C++, use the .mm extension.

      .cpp, .cxx are extensions for C++.

      You can check the content of the QtMacExtras module for simple examples on how to write Objective-C++.

      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
      2
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #2

        I assume you mean that your source code generates errors/warnings when your compiler sees it, because Qt is a library: it does not "recognize" the C++/Python/whatever source code of your program logic. Errors and warnings would not be surprising if you are feeding something that is not C++ or C to a C++ compiler.

        Perhaps you could share your project file and some hints about the error/warning?

        S 1 Reply Last reply
        1
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #3

          Are you adding .m files to OBJECTIVE_HEADERS and OBJECTIVE_SOURCES in your .pro file?

          https://doc.qt.io/qt-5/qmake-variable-reference.html#objective-headers

          (Z(:^

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

            Hi,

            Are you trying to put that in a .cpp file ?

            If so that's normal, this is not valid C++.

            If you want to do Objective-C++ (mixing Objective-C and C++ code) then you have to write a .mm file.

            Depending on your version of Qt you have to put these files under "OBJECTIVE_SOURCES" in your .pro file.

            Depending on the framework you use, you also need to add the proper information to the LIBS variable.

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

            S 1 Reply Last reply
            3
            • SGaistS SGaist

              Hi,

              Are you trying to put that in a .cpp file ?

              If so that's normal, this is not valid C++.

              If you want to do Objective-C++ (mixing Objective-C and C++ code) then you have to write a .mm file.

              Depending on your version of Qt you have to put these files under "OBJECTIVE_SOURCES" in your .pro file.

              Depending on the framework you use, you also need to add the proper information to the LIBS variable.

              S Offline
              S Offline
              senmx
              wrote on last edited by
              #5

              @SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?

              SGaistS 1 Reply Last reply
              0
              • sierdzioS sierdzio

                Are you adding .m files to OBJECTIVE_HEADERS and OBJECTIVE_SOURCES in your .pro file?

                https://doc.qt.io/qt-5/qmake-variable-reference.html#objective-headers

                S Offline
                S Offline
                senmx
                wrote on last edited by
                #6

                @sierdzio Tks, this is added.

                1 Reply Last reply
                0
                • C ChrisW67

                  I assume you mean that your source code generates errors/warnings when your compiler sees it, because Qt is a library: it does not "recognize" the C++/Python/whatever source code of your program logic. Errors and warnings would not be surprising if you are feeding something that is not C++ or C to a C++ compiler.

                  Perhaps you could share your project file and some hints about the error/warning?

                  S Offline
                  S Offline
                  senmx
                  wrote on last edited by
                  #7

                  @ChrisW67 Tks. Objective-C and C++ can be mixed originally, the problem only how mixed them.

                  1 Reply Last reply
                  0
                  • S senmx

                    @SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @senmx said in Qt does not recognize objective-c header files?:

                    @SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?

                    No, pure Objective-C is written in .m files. If you want to mix Objective-C and C++, use the .mm extension.

                    .cpp, .cxx are extensions for C++.

                    You can check the content of the QtMacExtras module for simple examples on how to write Objective-C++.

                    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
                    2

                    • Login

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