gpt4 book ai didi

cocoa - Qt5。 QMacNativeWidget。体系结构 x86_64 的 undefined symbol

转载 作者:行者123 更新时间:2023-12-03 17:23:15 24 4
gpt4 key购买 nike

QMacNativeWidget 在 Qt5 文档中列出,但任何尝试使用嵌入式 Qt Widget 创建 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());)时,应用程序链接成功,但在运行时创建了附加窗口。(

Screenshot

我的问题:我做错了什么还是Qt问题?谢谢!

最佳答案

这里有同样的问题。我解决了将文件扩展名从“.cpp”更改为“.mm”的问题。我在一些 QtBug 描述中看到这个技巧,尝试过并且对我有用(使用静态构建的 Qt 5.7)。 .mm 扩展名用于 Objective-C++ 代码(Objective-C 和 C++ 的混合体)。使用 .cpp 扩展名时出现“ undefined symbol ”错误。

关于cocoa - Qt5。 QMacNativeWidget。体系结构 x86_64 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14817278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com