【发布时间】:2018-08-21 00:15:19
【问题描述】:
我正在关注Qt's guide,因为我使用了QPushButton。
我完全按照指南的建议进行操作,但出现编译错误:
./src/mainwindow.o: In function `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:(.text+0x1d): undefined reference to `vtable for MainWindow'
./src/mainwindow.o:mainwindow.cpp:(.text+0x25): more undefined references to `vtable for MainWindow' follow
collect2: error: ld returned 1 exit status
make: *** [HelloWorldProj] Error 1
我尝试添加一个析构函数:
~MainWindow(){};
但问题仍然存在。
我没有声明任何虚函数,除了QMainWindow(我继承的类)中的一个函数:
virtual QMenu *createPopupMenu();
这应该在我的课堂上定义吗?
【问题讨论】:
-
将
Q_OBJECT添加到您的类声明中,运行 qmake 并再次构建。 -
我有一个
Q_OBJECT:class MainWindow : public QMainWindow { Q_OBJECT...} -
改进你的问题。
-
我的确切代码就像链接的网站。我没有什么可以添加到我的问题...
-
我已经更新了网站上的示例,以包含示例运行所需的 pro 文件。