gpt4 book ai didi

c++ - 具有虚函数的类,当派生自 QObject 时,会导致链接错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:11:36 33 4
gpt4 key购买 nike

下面是运行良好的代码

class HttpService {
public:
virtual ~HttpService(); // implemented in .cpp
protected:
HttpService(struct MHD_Connection *conn) {}
};
class HttpFileService : public HttpService
{
public:
virtual ~HttpFileService() ; // implemented in .cpp
protected:
HttpFileService(struct MHD_Connection *conn) : HttpService(conn) {}
};

现在,当我将 HttpService 设为 QObject 的派生类时,如下所示:

#include <QObject>                      // change #1
class HttpService : public QObject { // change #2
Q_OBJECT // change #3
public:
virtual ~HttpService();
protected:
HttpService(struct MHD_Connection *conn) {}
};

class HttpFileService : public HttpService {
Q_OBJECT // change #4
public:
virtual ~HttpFileService() ;
protected:
HttpFileService(struct MHD_Connection *conn) : HttpService(conn) {}
};

我遇到以下链接错误:

Undefined symbols for architecture x86_64:
"vtable for HttpService", referenced from:
HttpService::~HttpService()in httpservice.o

HttpService 的构造函数更改为以下内容也无济于事

explicit HttpService(QObject *parent = 0) : QObject(parent)

最佳答案

强制运行 qmake 并查看它是否有效。

关于c++ - 具有虚函数的类,当派生自 QObject 时,会导致链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7103964/

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