[英]Qt: undefined reference to `vtable for
When I try to compile my program I get the error 当我尝试编译程序时,出现错误
obj/backgroundWorker.o: In function `BackgroundWorker':
.../backgroundWorker.cpp:6: undefined reference to `vtable for BackgroundWorker'
obj/backgroundWorker.o: In function `~BackgroundWorker':
.../backgroundWorker.cpp:14: undefined reference to `vtable for BackgroundWorker'
I already found numerous reasons for this error, but so far, I couldn't solve the problem in my code: 我已经找到许多导致此错误的原因,但是到目前为止,我无法在代码中解决问题:
backgroundWorker.hpp backgroundWorker.hpp
#include <QObject>
#include <QPushButton>
class BackgroundWorker : public QWidget{
Q_OBJECT
public:
explicit BackgroundWorker();
~BackgroundWorker();
private slots:
void start();
private:
QPushButton* mStartButton;
};
backgroundWorker.cpp backgroundWorker.cpp
#include <iostream>
#include "getInput.hpp"
#include "backgroundWorker.hpp"
#include "LIF_network.hpp"
BackgroundWorker::BackgroundWorker(){
mStartButton = new QPushButton("Start",this);
mStartButton->setGeometry(QRect(QPoint(100,100),QSize(200,50)));
connect(mStartButton, SIGNAL(released()), this, SLOT(start()));
}
BackgroundWorker::~BackgroundWorker(){
delete mStartButton;
}
void BackgroundWorker::start(){
//stuff not related to qt
}
main.cpp main.cpp中
#include <QApplication>
#include "backgroundWorker.hpp"
int main(int argc, char *argv[]){
QApplication a(argc, argv);
BackgroundWorker bw;
return a.exec();
}
** .pro file** ** .pro文件**
CONFIG += qt debug c++11
QT += widgets
QMAKE_CC = clang++
QMAKE_CXX = clang++
QMAKE_CXXFLAGS += -Wall -Werror -O3
Headers += image.hpp \
getInput.hpp \
LIF_network.hpp \
backgroundWorker.hpp \
SOURCES += main.cpp \
image.cpp \
getInput.cpp \
LIF_network.cpp \
backgroundWorker.cpp \
OBJECTS_DIR = ./obj
As Frank Osterfeld mentioned in the comment the proper name for the variable is upper case HEADERS
. 正如Frank Osterfeld在评论中提到的那样,变量的专有名称是大写
HEADERS
。 And it should contain the list of all headers that have Q_OBJECT
macro in them 并且它应该包含其中具有
Q_OBJECT
宏的所有标头的列表
This is required because qmake needs to know the list of header files to feed to the moc
. 这是必需的,因为qmake需要知道要发送到
moc
的头文件列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.