1

我正在尝试用 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

请帮我解决这些错误..

4

2 回答 2

3

You must be using QT 4.8.x or older. All version before QT 5.x are compiled with

/Zc:wchar_t- 

(it means: DO NOT treat WChar_t as built in type) which is not compatible with MFC, BOOST or CUDA libraries. You need to switch to QT 5.x in which the flag changed to

/Zc:wchar_t

(without "minus" on the end) - it is compiled this way (they considered this as a flaw).

Or compile older version with /Zc:wchar_t, by changing it in source file:

QTSRC\mkspecs\win32-msvc2010\qmake.conf
于 2013-06-14T19:52:11.800 回答
1

我只能猜测,但是如果您在类定义之后缺少最后一个分号,或者在任何时候缺少右括号,您有时会遇到此类错误。

class XXX
{
};  // <- this one could be missing

在您的 CSettings.cpp 中,检查您在 QIODevice 或 QDebug 之前直接包含的文件。这通常是错误的类(可能是 CSettings.h)

于 2012-08-17T09:31:58.273 回答