Qt does not recognize objective-c header files?
-
wrote on 17 Sept 2021, 00:20 last edited by senmx
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; ...
-
@SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?
@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++.
-
wrote on 17 Sept 2021, 07:47 last edited by
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?
-
Are you adding .m files to
OBJECTIVE_HEADERS
andOBJECTIVE_SOURCES
in your .pro file?https://doc.qt.io/qt-5/qmake-variable-reference.html#objective-headers
-
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.
-
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.
-
Are you adding .m files to
OBJECTIVE_HEADERS
andOBJECTIVE_SOURCES
in your .pro file?https://doc.qt.io/qt-5/qmake-variable-reference.html#objective-headers
-
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?
-
@SGaist Tks. So objective-c code can only be typing in .mm files. .h or .cpp are considered standard C++ code?
@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++.
1/8