【问题标题】:Qt: Objective-C header gets compiled as c++-header [duplicate]Qt:Objective-C 标头被编译为 c++-header [重复]
【发布时间】:2023-03-27 05:09:01
【问题描述】:

我目前正在尝试实现 PIMPL-Idiom 以将 Objective-C 功能封装在 Qt 中的 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

ObjCHelper.h 是 Objective-C 标头

#import "HelperInterface.h"

@interface ObjCHelper : NSObject { int someVar }
- (int) doSomething():(void *)param;
@end

ObjCHelper.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 将 Objective-C 头文件 ObjCHelper.h 视为普通的 c++ 头文件!为什么会这样?

头文件ObjCHelper.h 不包含在ObjCHelper.mm 之外的任何其他位置

【问题讨论】:

    标签: c++ objective-c qt pimpl-idiom


    【解决方案1】:

    可能是 https://bugreports.qt.io/browse/QTBUG-36575 的一个实例,在 Qt 5.6 中由 https://codereview.qt-project.org/#/c/77117/ 修复。

    【讨论】:

      猜你喜欢
      • 2016-11-20
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-03
      • 1970-01-01
      相关资源
      最近更新 更多