qt编程时,遇到undefined reference to `vtable for xxx'怎么办

哎哎10年前 (2016-08-18)C++7377

今天编译某个arm程序时,添加了个

Q_OBJECT 的宏

然后编译报错


arm-none-linux-gnueabi-g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/QtEmbedded-4.7.0-arm/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/QtEmbedded-4.7.0-arm/include/QtCore -I/usr/local/Trolltech/QtEmbedded-4.7.0-arm/include/QtNetwork -I/usr/local/Trolltech/QtEmbedded-4.7.0-arm/include -I. -o contrlrtu.o contrlrtu.cpp
arm-none-linux-gnueabi-g++ -Wl,-O1 -Wl,-rpath,/usr/local/Trolltech/QtEmbedded-4.7.0-arm/lib -o arm_Udp_Bind_Serial_Send main.o udpbind_con.o rcvmsgprint.o contrlrtu.o moc_udpbind_con.o moc_rcvmsgprint.o    -L/usr/local/Trolltech/QtEmbedded-4.7.0-arm/lib -lQtNetwork -L/home/develop/yizhi/GUI/tslib/installdir/lib -L/usr/local/Trolltech/QtEmbedded-4.7.0-arm/lib -lQtCore -lpthread 
contrlrtu.o: In function `ContrlRtu::ContrlRtu(QObject*)':
contrlrtu.cpp:(.text+0x1c): undefined reference to `vtable for ContrlRtu'
contrlrtu.o: In function `ContrlRtu::~ContrlRtu()':
contrlrtu.cpp:(.text+0x6c): undefined reference to `vtable for ContrlRtu'
collect2: ld returned 1 exit status
make: *** [arm_Udp_Bind_Serial_Send] 错误 1


解决方法:


make clean

qmake

make

即可,因为新加的Q_OBJECT宏没有被moc,所以会导致,编译出错。

相关文章

使用QT设计师,快速将 ACTIONS 放入toolbar中

使用QT设计师,快速将 ACTIONS 放入toolbar中

  网上很多例子,都是手动敲代码在Qt界面工具栏中插入Action,实际QTDesigner本身带有其功能,而且非常方便。  插入完界面后,我们还可以去看它生成的代码,了解一下如何手动插入工具栏按钮。...

行文本编辑框QLineEdit及自动补全

行文本编辑框QLineEdit及自动补全

导读      行文本输入框在用于界面的文本输入,在WEB登录表单中应用广泛。一般行文本编辑框可定制性较高,既可以当作密码输入框,又可以作为文本过滤器。QLineEdit...

QSqlTableModel,使用简单教程。

Qt  QSqlTableModel  使用心得连接数据库执行sql查询,条件显示,排序获取记录数,列数以及记录内容,字段内容新增,修改,删除,恢复其它 &nb...

好久没更新了,这次介绍 qDebug()的所有输出转移至文件中

#include <QtDebug> #include <QFile> #include <QTextStream> #defi...

Gist一直可用

136 人赞同了该回答Github作为代码分享平台在开发者中非常流行。此平台托管了包括游戏、书籍以至于字体在内的一千两百多万个项目(现在更多),这使其成为互联网上最大的代码库。Github还提供另一个...

vs2022使用c++ std::any_of 等 c++ 11 标准语言时,提示报错namespace "std" has no member "all_of"

vs2022使用c++ std::any_of 等 c++ 11 标准语言时,提示报错namespace "std" has no member "all_of"...