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

编译问题

先来看一下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编译器根据类源文件自动生成的代码。

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

最新文章

  1. 【.NET深呼吸】元组数据(Tuple)
  2. SharePoint 2013 报:网站在改进过程中处于只读状态,对此给您带来的不便,我们深表歉意
  3. c++虚函数的作用是什么?
  4. 如何在Xcode6中添加空模板
  5. 分享9款用HTML5/CSS3制作的动物人物动画
  6. 安卓Design包之TabLayout控件的使用
  7. xcode升级或者重新安装后不能编译的解决方法
  8. jQuery循环给某个ID赋值
  9. js实现键盘操作对div的移动或改变-------Day43
  10. 关于DDOS攻击中TCP半连接数与FD的关系
  11. strcpy()、memcpy()、memmove()、memset()的内部实现
  12. CentOS 6.4 利用 Awstats 7.2 分析 Nginx 日志
  13. bootstrap+masonry.js写瀑布流
  14. shiro过滤器详解分析
  15. JS中this的四种用法
  16. web页面font-family显示
  17. LINUX-redis &amp; mongodb
  18. Mybatis教程-实战看这一篇就够了
  19. webservice------UDDI SOAP WSDL 之间的关系
  20. C#中数据库事务、存储过程基本用法

热门文章

  1. pytest框架使用教程
  2. 攻防世界FlatScience
  3. node+express实现简单的增删改查
  4. Linux05 /nginx
  5. 数据可视化之分析篇(一)使用Power BI进行动态帕累托分析
  6. JavaWeb项目的目录结构解释(上):
  7. Spring Boot中Tomcat是怎么启动的
  8. bzoj3289Mato的文件管理
  9. Trie——解决字符串搜索、异或最值问题
  10. JAVA集合一:ArrayList和LinkedList