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 # 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

2. 添加baseClass

baseclass.h

#ifndef BASECLASS_H
#define BASECLASS_H #include "QObject" class baseClass: public QObject
{
Q_OBJECT public:
baseClass(QObject * p = );
virtual ~baseClass() {} signals:
void signal1(); }; #endif // BASECLASS_H

baseClass.cpp

#include "baseclass.h"

baseClass::baseClass(QObject * p) : QObject(p)
{ }

subclass.h

#ifndef SUBCLASS_H
#define SUBCLASS_H #include "baseclass.h" class subClass: public baseClass
{
Q_OBJECT public:
subClass(QObject * p = );
virtual ~subClass() {}; //signals:
void signal2(); }; #endif // SUBCLASS_H

subclass.cpp

#include "subclass.h"

subClass::subClass(QObject * p) : baseClass (p)
{ }

main.cpp

#include <QCoreApplication>
#include "subclass.h" int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv); subClass * sub = new subClass(); return a.exec();
}

编译报错:

testQtSignalBug/subclass.cpp:: error: undefined reference to `vtable for subClass'

collect2: error: ld returned  exit status

解决办法:注释掉subclass.h里的Q_OBJECT 宏

原因:未知

qt undefined reference to `vtable for subClass'的更多相关文章

  1. Qt :undefined reference to vtable for "xxx::xxx"

    现象: 类加上宏 Q_OBJECT 就会报错 :undefined reference to vtable for "xxx::xxx" 解决方法: 重新 qmake 其他情况,查 ...

  2. (转) Qt 出现“undefined reference to `vtable for”原因总结

    由于Qt本身实现的机制所限,我们在使用Qt制作某些软件程序的时候,会遇到各种各样这样那样的问题,而且很多是很难,或者根本找不到原因的,即使解决了问题,如果有人问你为什么,你只能回答--不知道. 今天我 ...

  3. Qt经典出错信息之undefined reference to `vtable for classname

    原文链接:Qt经典出错信息之undefined reference to `vtable for classname 这个出错信息太常见了,用过Qt两个月以上的朋友基本上都能自己解决了,因为太经典了, ...

  4. Qt的“undefined reference to `vtable for”错误解决(手动解决,加深理解)

    使用QT编程时,当用户自定义了一个类,只要类中使用了信号或槽. Code::Blocks编译就会报错(undefined reference to `vtable for). Google上有很多这个 ...

  5. Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法

    在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...

  6. Qt 出现“undefined reference to `vtable for”

    在QT中定义了一个线程类,继承自QThread, 在类中未加 Q_OBJECT 时编译正常,加入后报错如下: undefined reference to `vtable for myThread' ...

  7. Qt - 错误总结 - 在自定义类头文件中添加Q_OBJECT 编译时报错(undefined reference to ‘vtable for xxThread)

    错误提示:在添加的QThread子类头文件添加Q_OBJECT时,编译程序,出现"undefined reference to 'vtable for xxThread'"错误提示 ...

  8. Qt 编译出错“undefined reference to `vtable for”

    1. 有时,如果将某个类改为继承自QObject类(以前不继承自该类),编译时会出错. 解决: clean Project, run qmake, rebulid都运行一遍,好了! 因为qmake生成 ...

  9. C++:undefined reference to vtable 原因与解决办法[转]

    [转]undefined reference to vtable 原因与解决办法 最近在写一套基础类库用于SG解包blob字段统计,在写完了所有程序编译时遇到一个郁闷无比的错误: MailBox.o( ...

随机推荐

  1. buuctf@test_your_nc

    测试你的 nc 技巧 :)

  2. Python Number(数字) Ⅱ

    Python math 模块.cmath 模块 Python 中数学运算常用的函数基本都在 math 模块.cmath 模块中. Python math 模块提供了许多对浮点数的数学运算函数. Pyt ...

  3. 016:URL命名与反转URL

    为什么需要URL命名? 主要解决蛋疼url变化情况,比如:哪天项目经理或领导过来说,把login改成signin,把register改成signup等蛋疼的需求——因为一旦改了url后,相关视图函数里 ...

  4. mysql NULL函数 语法

    mysql NULL函数 语法 作用:如果表中的某个列是可选的,那么我们可以在不向该列添加值的情况下插入新记录或更新已有的记录.这意味着该字段将以 NULL 值保存. 说明:NULL 值的处理方式与其 ...

  5. Linux小记 -- 更新系统软件包

    系统信息 操作系统:Ubuntu 18.04.2 LTS 内核版本:4.15.0-51-generic 何时需要更新 重新启动Ubuntu发现如下motd(message of tody),此时需要更 ...

  6. always_populate_raw_post_data

    Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a futu ...

  7. Linux_Comand - Check disk space

    df -h du -sh Delete folder older than 30 days find /path -name "test-*" -type d -mtime +30 ...

  8. heap和stack区别

    转载自博客:https://www.cnblogs.com/perfy/archive/2012/09/06/2672946.html 1.heap是堆 ,stack是栈 2.stack的空间由操作系 ...

  9. java 重写和重载的区别

    重写:重写是子类的方法覆盖父类的方法,有两个重要特点 1.子类方法名和参数类型.个数必须和父类一样. 2.如果有返回值,则返回值类型也必须和父类一样. //父类 public class Bird() ...

  10. Linux_KVM虚拟机

    目录 目录 Hpyervisor的种类 安装KVM 使用virsh指令管理虚拟机 KVM虚拟机的网络设置 Hpyervisor的种类 hpyervisor:是一种VMM(Virtual Machine ...