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?
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!
I had a similar problem and it was solved using andref's feedback. Within QT Creator I simply:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With