Visual-Studio-2010 – Use Q_Object in the VS2010 project to provide unresolved external

I am trying to use the Q_OBJECT macro in a Visual Studio 2010 Ultimate project, and it gives me an unresolved external error:

< 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 guess you forgot to generate the MOC file (in this case, moc_Application.cpp) Add 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.

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.

Leave a Comment

Your email address will not be published.