< pre>1>Application.obj: error LNK2001: unresolved external symbol “public: virtual int __thiscall MyButton::qt_metacall(enum QMetaObject::Call,int,void * *)” (?qt_metacall@MyButton@@UAEHW4Call@QMetaObject@@ HPAPAX@Z)
1>Application.obj: error LNK2001: unresolved external symbol “public: virtual void * __thiscall MyButton::qt_metacast(char const *)” (?qt_metacast@MyButton@@UAEPAXPBD@Z)
1>Application.obj: error LNK2001: unresolved external symbol “public: virtual struct QMetaObject const * __thiscall MyButton::metaObject(void)const “(?metaObject@MyButton@@UBEPBUQMetaObject@@XZ)
I have a similar project using QMaker and solved it by cleaning the project and re-running qmake. The problem is that there is no “Qmake” button in VS!
I read a lot of articles like this one and finished everything they told me. Although it didn’t really help, because I already have some existing projects with .cpp and some header files, I I want to avoid creating a .pro file and move the code into it.
I have installed the VS Qt plugin, and it gave me the new cool “Qt” button on the VS panel, although it did not help to solve the unresolved External (maybe I don’t know how to use it correctly).
I ran the moc through a custom build tool in my Application.h file (the only one with Q_OBJECT) in VS, but it still didn’t help :
C:\Utilities\QtSDK\Desktop\Qt\4.8.1\msvc2010\bin\moc Application.h -o tmp\moc\moc_Application.cpp
What could cause my problem, and how can I solve it?
I’m trying this in Visual Studio 2010 Ultimate The Q_OBJECT macro was used in the project, and it gave me an unresolved external error:
1>Application.obj: error LNK2001: unresolved external symbol "public: virtual int __thiscall MyButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyButton@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>Application.obj: error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyButton::qt_metacast(char const *)" (?qt_metacast@MyButton@@UAEPAXPBD@Z)
1>Application.obj: error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyButton::metaObject(void)const "(?metaObject@MyButton@@UBEPBUQMetaObject@@XZ)
I have a similar project using QMaker, and through a clean project and re-run qmake To solve it. The problem is that there is no “Qmake” button in VS!
I read a lot of articles like this one and finished everything they told me. Although it didn’t really help, because I already have some existing projects with .cpp and some header files, I I want to avoid creating a .pro file and move the code into it.
I have installed the VS Qt plugin, and it gave me the new cool “Qt” button on the VS panel, although it did not help to solve the unresolved External (maybe I don’t know how to use it correctly).
I ran the moc through a custom build tool in my Application.h file (the only one with Q_OBJECT) in VS, but it still didn’t help :
C:\Utilities\QtSDK\Desktop\Qt\4.8.1\msvc2010\bin\moc Application.h -o tmp\moc\moc_Application.cpp
What could cause my problem, and how can I solve it?
I guess you forgot to add the MOC generated file (moc_Application.cpp in this case) to the Visual Studio project. You have to do this to Make sure it is built. I’m pretty sure this should solve the linker error you are seeing.