当前位置:网站首页>QT添加QObject类(想使用信号和槽)遇到的问题汇总,亲测解决有效error: undefined reference to `vtable for xxxxxx(你的类名)‘
QT添加QObject类(想使用信号和槽)遇到的问题汇总,亲测解决有效error: undefined reference to `vtable for xxxxxx(你的类名)‘
2022-06-12 11:49:00 【路漫漫其远,吾求索】
一:应用场景:
1,自己新建了一个父类,又新建了一个子类,继承了父类,想要在子类中使用信号和槽函数。结果发现connect函数不能使用。
二:实现步骤
1,添加头文件 #include
2,你的类要继承 public QObject
3,在类里面添加宏 Q_OBJECT
三:遇到问题
1,error: undefined reference to `vtable for xxxxxx(你的类名)‘。
2,error: undefined reference to xxxxx(这个是我的父类)::metaObject() const’。
3,在子类中实现的信号和槽函数,结果在使用的时候去父类中寻找槽函数,报找不到槽函数。
四:解决办法
1,既然是要在子类中使用,那就把父类中的QObject类相关的删除掉
2,在子类中把上面的实现步骤写一遍
3,既然是添加了Q_OBJECT这个宏,需要重新编译项目
4,点击qt的构建—>清理所有项目
5,清理完成之后,点击构建—>执行qmake(一定要先执行qmake,因为要把Q_OBJECT这个宏编译进去,重写Makefile),大部分人都没有执行这一步,才会异常
6,点击运行(80%的人都会成功)
7,如果运行成功,恭喜你,没有遇到一个很奇葩的bug,如果运行失败,看一下是不是我这种情况,非常神奇!
8,因为我的子类是继承的父类,所以在添加QObject类的时候,自然而然的把这个QObject写到了后面:如下图所示
9,这样执行会有问题,会报error
10,把QObject类,写到最前面,然后在重新编译就可以了,是不是很神奇
11,点击运行(99.9%的人都会成功)
12,如果你还不成功,那你在把那个实现步骤执行一遍,或者把这个类先删掉,然后重新添加一下,或者把那个build–debug/release编译目录,删掉,在重新编译一下,如果还不行,那就不知道了,哈哈。
五:运行成功
祝各位小伙伴运行成功,嘿嘿。
边栏推荐
- 字节序 - 如何判断大端小端
- Promise controls the number of concurrent requests
- C# 36. DataGridView行号
- UML series articles (30) architecture modeling -- product diagram
- Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
- conda环境下pip install 无法安装到指定conda环境中(conda环境的默认pip安装位置)
- [Blue Bridge Cup SCM 11th National race]
- First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware
- Node crawler puppeter usage
- 6.6 Convolution de séparation
猜你喜欢
随机推荐
QML学习 第二天
Unit test case framework --unittest
Mysql45 lecture 01 | infrastructure: how is an SQL query executed?
[database] SQLite version upgrade and downgrade
TinyMCE series (II) TinyMCE plug-in development
UML series articles (31) architecture modeling - deployment diagram
TinyMCE series (III) introduction to common TinyMCE APIs
kubernetes集群搭建
FPGA Development - Hello_ World routine
如何确定首页和搜索之间的关系呢?首页与搜索的关系
淘宝新改版商家如何操作,需要注意的点有哪些
机器学习之线性模型
TinyMCE realizes automatic uploading of pasted pictures
6.6 分離卷積
How to operate the newly revised Taobao merchants and what should be paid attention to
Summary of rosbridge use cases_ Chapter 26 opening multiple rosbridge service listening ports on the same server
ioremap
机器学习之决策树
ARM指令集之跳转指令
The second regular match is inconsistent with the first one, and the match in the regular loop is invalid







![[the 11th national competition of Blue Bridge Cup single chip microcomputer]](/img/da/3c8a9efd5b28f67816f239531a0339.png)

