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

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

今天编译某个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,所以会导致,编译出错。

相关文章

按位与、或、异或等运算方法

  按位与运算符(&)  参加运算的两个数据,按二进制位进行“与”运算。  运算规则:0&0=0; 0&1=0; 1&0=0; 1&1=1;  即:两位同时为“...

QT 中修改程序form图标,mainwindow图标

  1、通过qtcreator新建一个文件filename.qrc,将图片添加到filename.qrc文件中:选择Add Prefix得到/new/prefix1,简单点改为/,再选Add File...

【QT】QT QString 很全的使用

  QString, QByteArray, 和 QVariant这三个类和容器有许多相同之处,并且在一些情况下可以被当作特殊的容器。 同样,像容器,这些类使用隐式共享来优化内存和速度。  我们将从Q...

[qt5]qt5 的乱码解决办法

  今天在写一个程序的时候,发现代码在运行后 的QMessageBox 出现了乱码啊? 然后就使用QT4的解决方法 使用QTextCoder 还是不行...

[QT]qt 程序退出代码。

  1.关闭主窗口并退出程序是    QApplication::exit()     2.如果是QDialog,就accept() 或 reje...

[WINDDK]系统驱动开发,出现 __IN_ 未定义的类型解决方案。 vs2008 winddk

1>stdafx.cpp1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\excpt.h(60) : error C206...