Qt metaObject链接器问题 [英] Qt metaObject linker problem

查看:889
本文介绍了Qt metaObject链接器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在整合Qt与Vs,并试图编译.pro文件后,我得到以下错误:

 错误9错误LNK2001 :未解析的外部符号public:virtual int __thiscall Multiplication_dialog :: qt_metacall(enum QMetaObject :: Call,int,void * *)(?qt_metacall @ Multiplication_dialog @@ UAEHW4Call @ QMetaObject @@ HPAPAX @ Z)

错误7错误LNK2001:未解析的外部符号public:virtual struct QMetaObject const * __thiscall Multiplication_dialog :: metaObject(void)const(?metaObject @ Multiplication_dialog @@ UBEPBUQMetaObject @@ XZ)


Error 8 error LNK2001:未解析的外部符号public:virtual void * __thiscall Multiplication_dialog :: qt_metacast(char const *)(?qt_metacast @ Multiplication_dialog @@ UAEPAXPBD @ Z)
/ pre>

如何处理这个问题?

解决方案

当你的项目中没有编译/链接foo.h(包含你的类标记为Q_OBJECT)的moc_foo.cpp时,得到这些错误。



在VS中工作


  1. 使用'qmake -tp vc'或
  2. 创建.vcproj文件
  3. 使用Qt Visual Studio加载项,它会自动处理所有的moc魔术(不能用于VC Express版本)。

使用加载项时,您可以通过

触发创建moc_foo.cpp


  • 确保对象的头文件

  • 从Multiplication_dialog的头文件中删除所有出现的Q_OBJECT。
  • $ b $ b
  • 保存文件

  • 再次添加Q_OBJECT

  • 保存文件



现在您应该在解决方案资源管理器中的Generated Files文件夹中有两个版本的moc_multiplication_dialog.cpp。一个用于调试,一个用于释放。
确保这些文件之一从构建中排除。


After integrating Qt with Vs and trying to compile .pro file I'm getting following errors:

Error   9   error LNK2001: unresolved external symbol "public: virtual int __thiscall Multiplication_dialog::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Multiplication_dialog@@UAEHW4Call@QMetaObject@@HPAPAX@Z)     

Error   7   error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Multiplication_dialog::metaObject(void)const " (?metaObject@Multiplication_dialog@@UBEPBUQMetaObject@@XZ)  


    Error   8   error LNK2001: unresolved external symbol "public: virtual void * __thiscall Multiplication_dialog::qt_metacast(char const *)" (?qt_metacast@Multiplication_dialog@@UAEPAXPBD@Z)    

What to do with this?

解决方案

You usally get these errors when the moc_foo.cpp for foo.h (which contains your class marked with Q_OBJECT) is not compiled / linked in your project.

To make a Qt project work in VS you either

  1. Create a .vcproj file with 'qmake -tp vc' or
  2. Use the Qt Visual Studio Add-in which handles all the moc magic automatically for you (doesn't work with VC Express versions though).

When using the add-in you can trigger the creation of the moc_foo.cpp by

  • Make sure the header file of the object in question appears in the VS project
  • List item
  • remove all occurrances of Q_OBJECT from the header file of Multiplication_dialog.
  • save the file
  • add Q_OBJECT again
  • save the file

Now you should have two versions of moc_multiplication_dialog.cpp in your "Generated Files" folder in the Solution Explorer. One for "Debug" and one for "Release". Make sure that one of these files is not excluded from build.

这篇关于Qt metaObject链接器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆