今天调试代码时遇到一个奇怪的问题,不过一般感觉比较奇怪的问题,最后查到原因时,原因都比较简单!
编译错误出现一大堆,这里只贴了前面的一部分,来看下:
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 hereD:\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 hereD:\Qt\Qt5.10.0\5.10.0\mingw53_32\include/QtCore/qlist.h:462:28: error: invalid use of incomplete type 'class QVariant'
从错误里不太容易看出来错误原因和错误的代码位置,只能看到文件,是moc_test.cpp编译时引起的错误,可能和QVariant类型有关;
在代码中,没有使用QVariant类型的地方,使用QVariantLis的地方有两个,一个是信号的入参,一个是信号的入参,一个是函数的成员变量定义;我把这两个部分同时注释掉,发现编译可以通过了;单独注释掉信号定义,也可以编译过!这也是导致问题不好判断的地方。
后来加上头文件
#include <QVariantList>
然后就都可以编译通过了!
文章转载自嵌入式技术笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




