今天调试代码时遇到一个奇怪的问题,不过一般感觉比较奇怪的问题,最后查到原因时,原因都比较简单!

编译问题

先来看一下qt的编译错误,提示一堆错误:

In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qglobal.h:1173:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qnamespace.h:43,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qobjectdefs.h:48,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:46,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qtypeinfo.h: In instantiation of 'class QTypeInfo<QVariant>':
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:459:31: required from 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QVariant]'
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:813:22: required from 'QList<T>::QList(const QList<T>&) [with T = QVariant]'
temp\moc\moc_test.cpp:103:82: required from here
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qtypeinfo.h:67:26: error: invalid application of 'sizeof' to incomplete type 'QVariant'
isLarge = (sizeof(T)>sizeof(void*)),
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qtypeinfo.h:69:24: error: invalid application of 'sizeof' to incomplete type 'QVariant'
sizeOf = sizeof(T)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h: In instantiation of 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QVariant]':
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:813:22: required from 'QList<T>::QList(const QList<T>&) [with T = QVariant]'
temp\moc\moc_test.cpp:103:82: required from here
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:462:28: error: invalid use of incomplete type 'class QVariant'
current->v = new T(*reinterpret_cast<T*>(src->v));
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:468:17: warning: possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
delete reinterpret_cast<T*>(current->v);
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:468:17: warning: invalid use of incomplete type 'class QVariant'
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:468:17: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
delete reinterpret_cast<T*>(current->v);
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:475:17: error: invalid use of incomplete type 'class QVariant'
new (current) T(*reinterpret_cast<T*>(src));
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:481:17: error: invalid use of incomplete type 'class QVariant'
(reinterpret_cast<T*>(current))->~T();
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h: In instantiation of 'void QList<T>::node_destruct(QList<T>::Node*, QList<T>::Node*) [with T = QVariant]':
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:865:18: required from 'void QList<T>::dealloc(QListData::Data*) [with T = QVariant]'
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:827:16: required from 'QList<T>::~QList() [with T = QVariant]'
temp\moc\moc_test.cpp:103:82: required from here
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:494:31: warning: possible problem detected in invocation of delete operator: [-Wdelete-incomplete]
while(from != to) --to, delete reinterpret_cast<T*>(to->v);
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:494:31: warning: invalid use of incomplete type 'class QVariant'
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:49:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:494:31: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined
while(from != to) --to, delete reinterpret_cast<T*>(to->v);
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:496:32: error: invalid use of incomplete type 'class QVariant'
while (from != to) --to, reinterpret_cast<T*>(to)->~T();
^
In file included from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/qobject.h:54:0,
from D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtCore/QObject:1,
from temp\moc\../../../test/module_function/test.h:4,
from temp\moc\moc_test.cpp:9:
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:114:21: note: forward declaration of 'class QVariant'
F(QVariant, 41, QVariant) \
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1924:11: note: in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
class Name;
^
D:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qmetatype.h:1926:1: note: in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
QT_FOR_EACH_STATIC_CORE_CLASS(QT_FORWARD_DECLARE_STATIC_TYPES_ITER)
^
Makefile.Debug:3709: recipe for target 'temp/obj/moc_test.o' failed
mingw32-make[1]: Leaving directory 'E:/code/test-Debug'
Makefile:36: recipe for target 'debug' failed
mingw32-make[1]: *** [temp/obj/moc_test.o] Error 1
mingw32-make: *** [debug] Error 2
18:04:40: 进程"D:\Qt\Qt5.10.0\Tools\mingw530_32\bin\mingw32-make.exe"退出,退出代码 2 。
Error while building/deploying project test (kit: Desktop Qt 5.10.0 MinGW 32bit)
When executing step "Make"

排查问题

从这里面可以看出,基本上是与QVariant类型的使用有关系,查了下代码,里面没有直接使用QVariant类型的地方,到是有一个信号的参数类型,使用的是QVariantList,怀疑有可能是这个信号引起的,把这信号注释掉之后,编译不在报错。然后类里面的成员变量里使用QVariantList定义的成员变量,则不会导致这个编译错误!

另外,通过查看编译错误,可以发现,是编译moc_test.cpp文件时开始报错的,也就是说,在编译moc文件时提示报错,moc文件里第9行是#include " temp\moc\../../../test/module_function/test.h",引用的是测试类的头文件,也看不出什么错误。

只是尝试给test.h里加了个头文件引用:#include <QVariantList>,再次编译错误没有了,编译通过!

问题原因

使用QVariantList作为信号的参数时,一定引用头文件:

#include  <QVariantList>

否则会编译错误,如果不作为信号的参数,只是作为成员变量用,或者成员函数的参数,不引用其头文件也不会报错。

这两种情况编译是有点区别的,moc文件是qt编译器根据类源文件自动生成的代码。

在此记录一下,以免以后调试遇到同样的问题而浪费时间。

Qt信号参数中使用QVariantList时编译问题的更多相关文章

  1. ASP.NET Core3.0 中的运行时编译

    运行时编译 通过 Razor 文件的运行时编译补充生成时编译. 当 .cshtml 文件的内容发生更改时,ASP.NET Core MVC 将重新编译 Razor 文件 . 通过 Razor 文件的运 ...

  2. Qt信号槽中槽函数为虚函数的一些感想

    有时候,在写connect的时候会去犹豫一个问题----我的槽函数到底需不需要为虚函数.这个问题在我每次写connect的时候我都会反问自己,因为确实,如果你不去深究里面的moc,你发现不了太多问题. ...

  3. Python2在Sublime Text3中print中文时编译报错解决办法

    如果是用记事本新建的python文件,有可能是由于记事本默认的ascii格式导致的,这个时候只需要在Sublime Text3中   文件->设置文件编码(utf-8),保存即可.这样能够解决的 ...

  4. Qt安装过程中: configure 时发生的经典出错信息之”Basic XLib functionality test failed!”(Z..z..) 之 MySQL support cannot be enabled due to functionality test!

    整出错信息是在./configure阶段Basic XLib functionality test failed!You might need to modify the include and li ...

  5. js传递参数中包含+号时的处理方法

    encodeURI(url).replace(/\+/g, '%2B') 例子: $scope.getAnesthesiawaystatistical = function (annual, anes ...

  6. QT信号槽 中的对象野指针

    例: connect(&objec1,&class::slot_func1,&object2,&class::slot_func2) 如果 &objec   传 ...

  7. 7z命令行参数中的路径

    最近在自动化的过程中用到了7z命令行工具,发现其参数中的路径挺有意思的,在此总结一下.本文中所有demo使用的7z版本为:15.14 x64. 压缩某个文件夹 下面的命令会把g:\temp\目录和目录 ...

  8. qt设计器中使用自定义控件

    当qt设计器中的控件不能满足需要时,这时就要自定义控件.然后再在qt设计器中使用. 在qt设计器中使用自定义控件时,可以用提升. 从控件派生出新的类: 然后在qt设计器中右键需要提升的控件: 填入提升 ...

  9. axios中get请求的params参数中带数组的处理方法

    axios中get请求的params参数中带数组时导致向后台传参失败报错:from origin 'http://localhost:8080' has been blocked by CORS po ...

随机推荐

  1. Spring的学习与实战

    目录 一.Spring起步 学习路线图 Spring的基础知识 什么是Spring Spring框架核心模块 SpringBoot 第一个Spring应用DEMO 编写自己的第一个SpringMVC例 ...

  2. node+express+static完成简单的文件下载

    不多说什么,直接上代码 var express = require('express'); var fs = require('fs') var path= require('path'); var ...

  3. selenium报错Element is not clickable at point及四种解决方法

    使用Selenium时,触发点击事件,经常报如下异常:Element is not clickable at point 1.未加载没加载出来就等待元素加载出来,再往下执行.可以使用python库ti ...

  4. ASP.NET Core静态文件处理源码探究

    前言     静态文件(如 HTML.CSS.图像和 JavaScript)等是Web程序的重要组成部分.传统的ASP.NET项目一般都是部署在IIS上,IIS是一个功能非常强大的服务器平台,可以直接 ...

  5. T4 分配时间 题解

    问题描述 小王参加的考试是几门科目的试卷放在一起考,一共给 t 分钟来做.他现在已经知道每 门科目花的时间和得到的分数的关系,还有写名字要的时间(他写自己的名字很慢)请帮他 算一下他最高能得几分.总分 ...

  6. Android调用摄像机拍照(只能拍一张,第二张自动替换)

    这两天我玩了玩几天没动的Android,脑子里冒出一个注意,想用Android调用摄像机(偷拍)拍照,然后存下来,在网上百度一下就有很多人说,我也试了试,7.0以下非常轻松就成功了,因为7.0一下不用 ...

  7. Bash 脚本编程

    概述 Bash (GNU Bourne-Again Shell) 是许多Linux发行版的默认Shell. shell语法 变量 定义:your_name="hellohhy" 使 ...

  8. 设计模式:mediator模式

    目的:解决多组件之间的通信问题,使得组件之间的通信变得简单 核心:提供一个管理类,用来处理组件之间的通信,所有的组件只和管理类通信,组件彼此之间不在单独通信 例子: class Mediator { ...

  9. 学会Python除了不能生孩子,其他的都能做。

    随着人工智能的迅猛发展,相信大家对于it行业最熟悉的词莫过于 Python.那么,Python究竟可以做些什么呢?一个资深程序员说:“学会Python除了不能生孩子,其他的都能做.”加入3137821 ...

  10. Python3基础语法快速入门

    01 Python 简介 Python 是一种高层次的结合了解释性.编译性.互动性和面向对象的脚本语言.Python 由 Guido van Rossum 于 1989 年底在荷兰国家数学和计算机科学 ...