初级问题,一个类继承QWidget,编译出错
- #include <QtGui/QtGui>
- class myclass : public QWidget
- {
- Q_OBJECT
- };
- int main(int argc, char **argv)
- {
- QApplication app(argc, argv);
- myclass myc;
- myc.show();
- return app.exec();
- }
复制代码
编译出错
_make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.4.3/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include -I. -I. -I. -o tmp.o tmp.cpp
g++ -Wl,-rpath,/usr/local/Trolltech/Qt-4.4.3/lib -o tmp tmp.o -L/usr/local/Trolltech/Qt-4.4.3/lib -lQtGui -L/usr/local/Trolltech/Qt-4.4.3/lib -L/usr/X11R6/lib -pthread -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
tmp.o: In function `main':
tmp.cpp.text+0x5e): undefined reference to `vtable for myclass'
tmp.cpp.text+0x65): undefined reference to `vtable for myclass'
tmp.cpp.text+0x76): undefined reference to `vtable for myclass'
tmp.cpp.text+0x82): undefined reference to `vtable for myclass'
tmp.cpp.text+0x8b): undefined reference to `vtable for myclass'
tmp.o:tmp.cpp.text+0xc9): more undefined references to `vtable for myclass' follow
collect2: ld returned 1 exit status
make: *** [tmp] Error 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么解决的?
貌似是要moc,所以分开头文件和cpp文件的编写才行,是这样吗?
已经解决了![](https://www.wenjiangs.com/wp-content/uploads/chinaunix/202206/icon_mrgreen.gif)