2013-02-11 84 views
1

QMacNativeWidget QT5文档中列出未定义的符号,但与嵌入式Qt控件创建Cocoa应用程序的任何企图给我一个错误:Qt5。 QMacNativeWidget。对于建筑x86_64的

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的问题? 谢谢!

+0

你链接了哪些库? – 2013-02-12 06:47:47

+1

使用这套库:'-lQt5Gui_debug -lQt5Core_debug -lQt5PlatformSupport_debug -lQt5PrintSupport_debug -lQt5Widgets_debug' – Vlad 2013-02-12 07:46:26

+3

只需接收来自Digia的电子邮件。他们告诉我,'QMacNativeWidget'现在是独立包[QtMacExtras]的一部分(http://qt.gitorious.org/qtplayground/qtmacextras)。这个软件包稍后将成为Qt的一部分(计划在Qt 5.1中使用)。 Qt5中'QMacNativeWidget'的文档是由错误产生的,他们稍后会处理它。 – Vlad 2013-02-13 13:09:00

回答

0

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