初级问题,一个类继承QWidget,编译出错

发布于 2022-08-19 05:21:17 字数 2744 浏览 11 评论 2

  1. #include <QtGui/QtGui>
  2. class myclass : public QWidget
  3. {
  4.         Q_OBJECT
  5. };
  6. int main(int argc, char **argv)
  7. {
  8.         QApplication app(argc, argv);
  9.         myclass myc;
  10.         myc.show();
  11.         return app.exec();
  12. }

复制代码
编译出错
_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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2022-08-20 16:57:33

怎么解决的?

貌似是要moc,所以分开头文件和cpp文件的编写才行,是这样吗?

银河中√捞星星 2022-08-20 03:16:50

已经解决了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文