gpt4 book ai didi

c++ - Qt:对`vtable 的 undefined reference

转载 作者:太空宇宙 更新时间:2023-11-04 13:22:25 25 4
gpt4 key购买 nike

当我尝试编译我的程序时出现错误

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'

我已经找到了这个错误的许多原因,但到目前为止,我找不到解决我的代码中的问题:

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

#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

#include <QApplication>
#include "backgroundWorker.hpp"

int main(int argc, char *argv[]){
QApplication a(argc, argv);
BackgroundWorker bw;
return a.exec();
}

** .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

最佳答案

正如 Frank Osterfeld 在评论中提到的,变量的专有名称是大写的 HEADERS。它应该包含所有包含 Q_OBJECT 宏的 header

这是必需的,因为 qmake 需要知道要提供给 moc 的头文件列表。

关于c++ - Qt:对`vtable 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34666162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com