我正在尝试用cppunit测试我的qt项目。测试项目使用MFC。 我正在使用Visual Studio 2010。
我已经包含了qt库,dll并在项目设置中进行了其他更改,例如添加预处理程序定义以编译我想要测试的cpp文件。但是当我编译这个cpp文件时,我得到了很多语法错误,位于qt头文件中。编译输出如下:
1>------ Build started: Project: my_tests, Configuration: Debug Win32 ------
1>cl : Command line warning D9025: overriding '/ZI' with '/Zi'
1>cl : Command line warning D9025: overriding '/GS' with '/GS-'
1>cl : Command line warning D9025: overriding '/Zc:wchar_t' with '/Zc:wchar_t-'
1> CSetting.cpp
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qiodevice.h(247): error C2143: syntax error : missing ')' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qiodevice.h(247): error C2143: syntax error : missing ';' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qiodevice.h(247): error C2805: binary 'operator <<' has too few parameters
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qiodevice.h(247): error C2059: syntax error : ')'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2143: syntax error : missing ')' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2143: syntax error : missing ';' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2805: binary 'operator <<' has too few parameters
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2988: unrecognizable template declaration/definition
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2059: syntax error : 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2065: 'T' : undeclared identifier
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(160): error C2059: syntax error : ')'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(178): error C2065: 'T' : undeclared identifier
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(180): error C2143: syntax error : missing ';' before '{'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(180): error C2447: '{' : missing function header (old-style formal list?)
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(190): error C2143: syntax error : missing ')' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(190): error C2143: syntax error : missing ';' before 'constant'
1>c:\qt\4.8.2\include\qtcore\../../src/corelib/io/qdebug.h(190): fatal error C1903: unable to recover from previous error(s); stopping compilation
请帮我解决这些错误..
答案 0 :(得分:3)
您必须使用QT 4.8.x或更早版本。 QT 5.x之前的所有版本都是用
编译的/Zc:wchar_t-
(表示:不要将WChar_t视为内置类型)与MFC,BOOST或CUDA库不兼容。 您需要切换到QT 5.x,其中标志更改为
/Zc:wchar_t
(最后没有“减号”) - 它以这种方式编译(他们认为这是一个缺陷)。
或者使用/ Zc:wchar_t编译旧版本,在源文件中更改它:
QTSRC\mkspecs\win32-msvc2010\qmake.conf
答案 1 :(得分:1)
我只能猜测,但是如果你在课程定义之后缺少最后一个分号,或者在任何一点都有一个结束括号,你有时会遇到这些错误。
class XXX
{
}; // <- this one could be missing
在您的CSettings.cpp中,在QIODevice或QDebug之前检查您直接包含的文件。这通常是错误的类(可能是CSettings.h)