QT error: undefined reference to `vtable for Net‘

报错

C:\Users\Administrator\Desktop\VideoHill\GikISearch\net.cpp:4: error: undefined reference to `vtable for Net'

以下是两个可能错误原因

1,未定义 Q_OBJECT

在头文件中加上

加上#include <QObject>,

改写继承QObject 和定义宏

class MyClaa: public QObject {
Q_OBJECT

如下

cpp 复制代码
#ifndef NET_H
#define NET_H

#include <QObject>

class MyClaa: public QObject {
    Q_OBJECT
//class Net
//{

public:
    explicit MyClaa(QObject *parent = nullptr);

private slots:

private:

};

#endif // NET_H

2,多处定义 Q_OBJECT

如果在其他比如mainwindow.h中定义过宏

删去多定义的宏,比如新建新的类不能定义这个宏。

cpp 复制代码
#ifndef NET_H
#define NET_H

#include <QObject>

class MyClaa: public QObject {
    //Q_OBJECT
//class Net
//{

public:
    explicit MyClaa(QObject *parent = nullptr);

private slots:

private:

};

#endif // NET_H
相关推荐
geovindu20 小时前
go: Flyweight Pattern
开发语言·设计模式·golang·享元模式
不是起点的终点20 小时前
【实战】Python 一键生成数据库说明文档(对接阿里云百炼 AI,输出 Word 格式)
数据库·python·阿里云
xyq202421 小时前
TypeScript中的String类型详解
开发语言
2301_813599551 天前
Go语言怎么做秒杀系统_Go语言秒杀系统实战教程【实用】
jvm·数据库·python
NCIN EXPE1 天前
redis 使用
数据库·redis·缓存
MongoDB 数据平台1 天前
为编码代理引入 MongoDB 代理技能和插件
数据库·mongodb
极客on之路1 天前
mysql explain type 各个字段解释
数据库·mysql
代码雕刻家1 天前
MySQL与SQL Server的基本指令
数据库·mysql·sqlserver
lThE ANDE1 天前
开启mysql的binlog日志
数据库·mysql
小糖学代码1 天前
LLM系列:1.python入门:15.JSON 数据处理与操作
开发语言·python·json·aigc