Mac QT Undefined symbols for architecture x86_64:解决方案

Mac QT Undefined symbols for architecture x86_64:解决方案

编译过程中会出现 Undefined symbols for architecture x86_64:错误信息

详细编译错误信息为

Undefined symbols for architecture x86_64:
  "TimerWidget::timerEvent(QTimerEvent*)", referenced from:
      vtable for TimerWidget in moc_timerwidget.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [EventDemo.app/Contents/MacOS/EventDemo] Error 1
10:12:13: 进程"/usr/bin/make"退出,退出代码 2 。
Error while building/deploying project EventDemo (kit: Desktop Qt 5.13.0 clang 64bit)
When executing step "Make"

原因就是在头文件TimerWidget类中中声明了

protected:
    void timerEvent(QTimerEvent *);

但是未在TimerWidget.cpp文件里实现就可以,在TimerWidget.cpp添加一下代码即可

void TimerWidget::timerEvent(QTimerEvent *e){

}

你可能感兴趣的:(QT踩坑之旅)