2012-08-17 26 views
1

我想用cppunit來測試我的qt項目。測試項目使用MFC。 我正在使用Visual Studio 2010.qt頭文件與2010年編譯錯誤

我已經包括了qt庫,dll,並在項目設置中做了其他更改,如添加預處理器定義以編譯我想測試的cpp文件。但是,當我編譯這個cpp的文件,我得到下面有很多語法錯誤,位於QT頭files..The編譯輸出的給定:

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 

請幫我看看這些錯誤..

回答

1

我只能猜測,但如果在類定義之後缺少最後一個分號,或者在任何點都丟失了閉括號,則有時會出現這些類型的錯誤。

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

在你的CSettings.cpp中,檢查你在QIODevice或QDebug之前直接包含哪個文件。這通常是錯誤的類(可能是CSettings.h)

+0

我已經檢查的所有headerfiles,包括CSettings.h。所有的分號和括號都在原地。 – Hariprasad 2012-08-17 11:00:27

+0

在包含Qt頭文件之前,我在所有的cpp文件中包含了StdAfx.h ...這是否導致了問題..? 在這種情況下可以解決什麼問題?因爲我必須在其他頭文件之前包含StdAfx.h,對嗎? – Hariprasad 2012-08-17 11:06:45

+0

嗯嘗試刪除Qt包括,看看你是否得到其他錯誤(除了「未知的符號」,當然) – 2012-08-17 11:07:11

3

您必須使用QT 4.8.x或更早版本。 QT 5.x的所有之前版本的編譯

/Zc:wchar_t- 

(它的意思是:不要把wchar_t的內置型),這是不符合MFC,升壓或CUDA庫兼容。 你需要切換到QT 5.x的,其中把標誌改爲

/Zc:wchar_t 

(不就完了「減」) - 這是編譯這樣(他們認爲這是一個缺陷)。

或編譯舊版本與/ ZC:wchar_t的,在源文件作修改:

QTSRC\mkspecs\win32-msvc2010\qmake.conf