Qt5文档中列出了QMacNativeWidget类,但是任何尝试使用嵌入式 Qt Widgets 创建 Cocoa 应用程序都会给我下一个错误:
Undefined symbols for architecture x86_64:
"QMacNativeWidget::QMacNativeWidget(void*)", referenced from:
-[AppDelegate loadUi] in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
这是我的代码:
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
std::auto_ptr<QWidget> nativeWidget;
...
}
// Qt Widget will be attached to this view
@property (weak) IBOutlet NSView *view;
@end
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self initQtIfNeeded];
[self loadUi];
}
-(void) initQtIfNeeded
{
QApplication* app = qApp;
if (app == 0)
{
puts("Creating new QApplication instance...");
QApplication::setDesktopSettingsAware(true);
QApplication::setAttribute(Qt::AA_MacPluginApplication, true);
int argc = 0;
app = new QApplication(argc, NULL);
...
}
}
-(void)loadUi
{
nativeWidget.reset(new QMacNativeWidget());
...
// Casting pointer (x86_64 with ARC)
void* winId = reinterpret_cast<void *>(nativeWidget->winId());
NSView *nativeWidgetNSView = (__bridge NSView*)winId;
// Attaching Qt Widget to NSView
[self.view addSubview:nativeWidgetNSView positioned:NSWindowAbove relativeTo:nil];
nativeWidget->setGeometry(0, 0, self.view.frame.size.width, self.view.frame.size.height);
...
nativeWidget->show();
}
当我使用 QWidget 而不是 QMacNativeWidget (即:)nativeWidget.reset(new QWidget());
应用程序成功链接但在运行时创建了附加窗口。(
我的问题:我做错了什么还是 Qt 问题?谢谢!