C++ Qt:Objective-C头被编译为C++-标题
我目前正在尝试在Prime>Qt中C++语言类中封装Objto-C功能。我的pro文件如下所示:C++ Qt:Objective-C头被编译为C++-标题,c++,objective-c,qt,pimpl-idiom,C++,Objective C,Qt,Pimpl Idiom,我目前正在尝试在Prime>Qt中C++语言类中封装Objto-C功能。我的pro文件如下所示: QT += core gui TARGET = testProject TEMPLATE = app SOURCES += main.cpp Helper.cpp HEADERS += HelperInterface.h Helper.h OBJECTIVE_SOURCES += ObjCHelper.mm OBJECTIVE_HEADERS += ObjCHelper.h objchalper
QT += core gui
TARGET = testProject
TEMPLATE = app
SOURCES += main.cpp Helper.cpp
HEADERS += HelperInterface.h Helper.h
OBJECTIVE_SOURCES += ObjCHelper.mm
OBJECTIVE_HEADERS += ObjCHelper.h
objchalper.h
是objective-C头
#import "HelperInterface.h"
@interface ObjCHelper : NSObject { int someVar }
- (int) doSomething():(void *)param;
@end
objchalper.mm
#import "ObjCHelper.h"
@implementation ObjCHelper
MyClassImpl::MyClassImpl() : self(NULL) { }
MyClassImpl::~MyClassImpl() {
[(id)self dealloc];
}
void MyClassImpl::init()
{
self = [[ObjCHelper alloc] init];
}
//...
@end
类MyClassImpl在HelperInterface中定义
当我尝试编译此项目时,我收到以下错误:
cannot find interface declaration for 'NSObject', superclass of 'ObjCHelper'
@interface ObjCHelper : NSObject
~~~~~~~~~~~~~~~~~~~~~ ^
< >我觉得QT把Objy-C头文件<代码> Objelp.H./Cu>作为一个普通的C++头文件处理!为什么会这样
头文件ObjCHelper.h
不包括在ObjCHelper.mm
中以外的任何位置,它可能是的一个实例,由Qt 5.6中修复
#import "ObjCHelper.h"
@implementation ObjCHelper
MyClassImpl::MyClassImpl() : self(NULL) { }
MyClassImpl::~MyClassImpl() {
[(id)self dealloc];
}
void MyClassImpl::init()
{
self = [[ObjCHelper alloc] init];
}
//...
@end