How to solve error LNK2001: unresolved external symbol?

2.2k views Asked by At

I am new to Qt and now I am developing a simple application in using Visual Studio 2008 and when am building the code, the following errors occur:

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

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

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

 error LNK2001: unresolved external symbol "public: static struct QMetaObject const Window::staticMetaObject" (?staticMetaObject@Window@@2UQMetaObject@@B)

 fatal error LNK1120: 4 unresolved externals

How can I solve these errors?

1

There are 1 answers

0
Dmitriy On

You need to run moc.exe on your header files that use Q_OBJECT macro or inherit from QObject. For simplicity just install this qt vs addin and it will add everything for you. You'll probably will need to generate a new project.