Alex Rivera | Logout

Qt metaObject linker problem

Asked 2011-07-10T17:56:37.430
22

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?

Edit
Report

2 Answers

18

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.

answered 2011-07-10T18:03:06.470
4

Well Today I faced probably the same problem. I know the thread is pretty old. But It may still help someone.

What happened in my case was moc was generating the moc_ .cpp files but VC doesn't know that It has to compile them too. So I manually added those moc generated files so that it compiles. and It worked.

answered 2012-08-22T15:05:30.083

Your Answer