Qt Q_OBJECT在Visual Studio 2010中创建链接器错误

问题描述:

我试图让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://*.com/questions/3031512/compiling-a-simple-qt-hello-world-application-within-visual-studio-2010-expre) – Mat 2012-08-05 05:18:42

这是一个用VS2010编译Qt的链接。
http://thomasstockx.blogspot.in/2011/03/qt-472-in-visual-studio-2010.html
按照他所说的所有步骤,可能这可能会帮助您解决您的问题。谢谢,

如果你添加Q_OBJECT到一个类然后确保你运行qmake!我曾与造物主合作过,但在尝试编译包含扩展QObject的类的代码之前,我有一个Q_OBJECT宏,但当我没有这样做时,我真的很奇怪的错误。