cannot convert from pointer to base class 'QObject' to pointer to derived class 'subClass' via virtual base 'baseClass'
QT 编译不过的另一个问题:
1. 新建一个console工程
QT -= gui CONFIG += c++ console
CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0. SOURCES += \
main.cpp \
baseclass.cpp \
subclass.cpp \
subclass2.cpp
#grandclass.cpp # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target HEADERS += \
baseclass.h \
subclass.h \
subclass2.h
#grandclass.h
2. 添加baseClass
baseclass.h
#ifndef BASECLASS_H
#define BASECLASS_H #include "QObject" class baseClass: public QObject
{
Q_OBJECT public:
baseClass(QObject * p = );
virtual ~baseClass() {} virtual void vMethod(int) = ; signals:
void signal1(); }; #endif // BASECLASS_H
baseclass.cpp
#include "baseclass.h" baseClass::baseClass(QObject * p) : QObject(p)
{ }
3. 添加subClass
subclass.h
#ifndef SUBCLASS_H
#define SUBCLASS_H #include "baseclass.h" class subClass: virtual public baseClass
{
Q_OBJECT public:
subClass(QObject * p = );
virtual ~subClass() {};
virtual void vMethod(int) = ; signals:
void signal2(); }; #endif // SUBCLASS_H
subclass.cpp
#include "subclass.h" subClass::subClass(QObject * p) : baseClass (p)
{ }
4. 添加subClass2
subclass2.h
#ifndef SUBCLASS2_H
#define SUBCLASS2_H #include "baseclass.h" class subClass2 : virtual public baseClass
{
Q_OBJECT public:
subClass2(QObject * p = 0); virtual void vMethod(int) = ; }; #endif // SUBCLASS2_H
subclass2.cpp
#include "subclass2.h" subClass2::subClass2(QObject * p) : baseClass (p)
{ }
5 main.cpp
#include <QCoreApplication>
#include "subclass.h"
//#include "grandclass.h" int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); //grandClass * sub = new grandClass(); return a.exec();
}
编译报错:/build-testQtSignalBug-Qt5_9_4_zynq-Debug/moc_subclass.cpp:68: error: cannot convert from pointer to base class 'QObject' to pointer to derived class 'subClass' via virtual base 'baseClass'
subClass *_t = static_cast<subClass *>(_o);
^
解决方法: 将subclass里的signals 删掉, 即不在subclass里声明信号量。
原因:不详。
cannot convert from pointer to base class 'QObject' to pointer to derived class 'subClass' via virtual base 'baseClass'的更多相关文章
- vptr, vtable, virtual base class table
#include <iostream> using namespace std; class X { int x, y, z; }; class Y: public virtual X { ...
- 为什么0x00400000是可执行文件的默认基址?EXE base address start with 400000H,Why is 0x00400000 the default base address for an executable?
DLL的默认基址是0x10000000,但EXE的默认基址是0x00400000.为什么EXE特别值?4 兆字节有什么特别之处它与x86上单页目录条目映射的地址空间量和1987年的设计决策有关.对EX ...
- C#基础知识系列七(base、this、new、override、abstract、virtual、static)
前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...
- C#基础知识(base、this、new、override、abstract、virtual、static)
前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...
- base、this、new、override、abstract、virtual、static
前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...
- virtual base classes
virtual base classes用来实现菱形继承解决多个重复subobject的问题 //: C09:VirtualBase.cpp // Shows a shared subobject v ...
- 剑指offer12:求解double类型的浮点数base和int类型的整数exponent的次方。 保证base和exponent不同时为0
1. 题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方.保证base和exponent不同时为0. 2. 思路和方法 分析: 由于 ...
- Springboot项目报错【java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader】
1.发生问题: 升级了JDK9,发现原先的springboot项目起不来了,以为是maven中jdk配置有问题. 于是在pom中添加了 <plugin> <groupId>or ...
- C++话题
1.多态地实现 A:C++中多态的实现原理是怎样的? Q:通过迟邦定技术(late binding)实现. 具体实现原理如下: 1. 基类中函数带virtual关键字,表示该方法为虚函数. 2. 子类 ...
随机推荐
- CSS3 的动画属性
通过 CSS3,我们能够创建动画,这可以在许多网页中取代动画图片.Flash 动画以及 JavaScript. ㈠@keyframes 规则 ⑴浏览器支持 Firefox 支持替代的 @-moz-ke ...
- HGOI20190810 省常中互测3
Problem A 夏洛特 若当前处在点$(x,y)$下一时刻可以向该点四周任意方向走动一步, 初始在$(0,0)$是否存在一条合法的路线满足下列$n$个限制: 每一个限制形如$t_i , x_i ...
- HDU 6089 Rikka with Terrorist (线段树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左 ...
- hive单用户多点模式配置
简介 单用户多点模式也称远程服务模式,用户非java客户端访问元数据库,在服务端启动MetaStoreServer,客户端利用Thrift协议通过MetaStoreServer访问元数据库. mysq ...
- Java实现QQ微信轰炸机1.2(斗图乞丐版)
之前有小可爱评论可以实现斗图的功能,原理上是行的通的,所以我就稍微改了一下,能够实现单个图片循环轰炸,如果大家感兴趣也可以自己探究实现多张图片循环轰炸,不废话了,直接上源码package QQWcha ...
- jQuery file upload --Multiple File Input Fields in One Form
The plugin can be applied to a form with multiple file input fields out of the box. The files are se ...
- nginx-location正则表达式匹配规则及动静分离
nginx-location正则表达式匹配规则及动静分离 发表于 2018年03月5日 | 分类于 nginx| 0 nginx,location常用正则表达式,及nginx动静分离 nginx ...
- python源码
初学者 GitHub - kennethreitz/pip-pop: Tools for managing requirements files. GitHub - kennethreitz/envo ...
- 新建一个浏览器APP
安卓开发环境准备好了,试试新建一个浏览器程序吧 1.Start a new Android Studio Project 2.选这个像微信一样的样式 3.选择语言和版本 4.等待创建完成,拖一个Web ...
- [mysql]root用户登录mysql,输入密码后报错:Access denied for user 'root'@'localhost'
问题如下: wangju-G4:~$ mysql -u root -p Enter password: ERROR (): Access denied for user 'root'@'localho ...