Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Q_OBJECT linker error!

I am receiving the following linker error when I build my application.

HIMyClass.obj:: error: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall CHIMyClass::metaObject(void)const " (?metaObject@CHIMyClass@@UBEPBUQMetaObject@@XZ) File not found : HIMyClass.obj

HIMyClass.obj:: error: unresolved external symbol "public: virtual void * __thiscall CHIMyClass::qt_metacast(char const *)" (?qt_metacast@CHIMyClass@@UAEPAXPBD@Z) File not found : HIMyClass.obj

HIMyClass.obj:: error: unresolved external symbol "public: virtual int __thiscall CHIMyClass::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@CHIMyClass@@UAEHW4Call@QMetaObject@@HPAPAX@Z) File not found : HIMyClass.obj

My class declaration is like

class CHIMyClass:public QDialog
{
   Q_OBJECT

   ....

};

When I comment Q_OBJECT the linker error goes off (and obviously I am not able to use signals and slots). I am using Qt Creator as IDE and Qt 4.5.3. When I give Rebuild All it's definite that QMake will be called. I guess that, its the generation of moc_* files is where the problem lies. I am using Windows XP and cl as the compiler.

What might be the reason behind this linker error?

like image 369
liaK Avatar asked Jul 16 '10 11:07

liaK


2 Answers

Such errors usually mean that you haven't added the header of your class to "HEADERS" variable in pro file (meta object compiler generates moc_ files only for headers listed in this variable). Remember to run qmake after you change .pro file!

like image 96
chalup Avatar answered Nov 20 '22 14:11

chalup


I had a similar problem and it was solved using andref's feedback. Within QT Creator I simply:

  1. Build/Clean all
  2. Build/Run qmake
  3. Build/Run
like image 13
sakisk Avatar answered Nov 20 '22 14:11

sakisk