2012-08-05 134 views
0

我試圖讓Qt與Visual Studio 2010一起工作。我已經構建了一個可以在調試器中運行的工作程序。但是,當我嘗試將Q_OBJECT宏添加到我的類時,它會生成一堆鏈接器錯誤。Qt Q_OBJECT在Visual Studio 2010中創建鏈接器錯誤

1>------ Build started: Project: qt_poop, Configuration: Debug Win32 ------ 
1>Build started 2012/08/05 12:58:56. 
1>InitializeBuildStatus: 
1> Creating "Debug\qt_poop.unsuccessfulbuild" because "AlwaysCreate" was specified. 
1>ClCompile: 
1> GLViewer.cpp 
1> Window.cpp 
1> main.cpp 
1> Generating Code... 
1>Link: 
1> LINK : c:\Users\abral\Documents\Visual Studio 2010\Projects\qt_poop\Win32\Debug\\qt_poop.exe not found or not built by the last incremental link; performing full link 
1>GLViewer.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall GLViewer::metaObject(void)const " ([email protected]@@[email protected]@XZ) 
1>GLViewer.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall GLViewer::qt_metacast(char const *)" ([email protected]@@[email protected]) 
1>GLViewer.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall GLViewer::qt_metacall(enum QMetaObject::Call,int,void * *)" ([email protected]@@[email protected]@@[email protected]) 
1>c:\Users\abral\Documents\Visual Studio 2010\Projects\qt_poop\Win32\Debug\\qt_poop.exe : fatal error LNK1120: 3 unresolved externals 
1> 
1>Build FAILED. 
1> 
1>Time Elapsed 00:00:07.50 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我看到其他人提出了一些類似的問題,似乎有什麼東西做的編譯器和建設部和一堆其他的非常複雜的技術的東西,我的初學者大腦並不理解呢。此外,它似乎很大程度上面向使用命令行來配置編譯器的用戶,但我使用的是VS,而且我真的很想保持這種狀態(基本上我只是想按下綠色箭頭,看到我的程序 - 就這些)。所以......如果有人能夠以儘可能簡單的方式向我解釋如何配置Visual Studio來執行任何鏈接或編譯或者它需要做什麼來完成此操作,我將永遠感激。

+2

QT創建者具有綠色箭頭,非常適合用QT編寫代碼。只是說' – 2012-08-05 04:54:45

+0

可能的重複[編譯一個簡單的Qt「Hello World!」)應用程序在Visual Studio 2010 Express?](http://stackoverflow.com/questions/3031512/compiling-a-simple-qt-hello-world-application-within-visual-studio-2010-expre) – Mat 2012-08-05 05:18:42

回答

0

如果你添加Q_OBJECT到一個類然後確保你運行qmake!我曾與造物主合作過,但在嘗試編譯包含擴展QObject的類的代碼之前,我有一個Q_OBJECT宏,但當我沒有這樣做時,我真的很奇怪的錯誤。