After integrating Qt with Vs and trying to compile .pro file I\'m getting following errors:
Error 9 error LNK2001: unresolved external symbol \"public
Try to relaunch the .pro of your project.
I'm currently working with VS 2013 with QT 5.4 add-in. Building projects with the add-in makes it easier as the moc'ing is automatically handled. To prevent linker error problems with the Qt metaObject issues:
Comment out all instances of Q_OBJECT in all header files that contain it in the class declarations.
Build the solution
Uncomment all instances of the Q_OBJECT in the header files.
Rebuild the solution. This is where the all the all the header and cpp files are re-compiled with the moc'ing automatically done. The linker errors are in turn, taken care of.
You usally get these errors when the moc_foo.cpp for foo.h (which contains your class marked with Q_OBJECT) is not compiled / linked in your project.
To make a Qt project work in VS you either
When using the add-in you can trigger the creation of the moc_foo.cpp by
Now you should have two versions of moc_multiplication_dialog.cpp in your "Generated Files" folder in the Solution Explorer. One for "Debug" and one for "Release". Make sure that one of these files is not excluded from build.
Well Today I faced probably the same problem. I know the thread is pretty old. But It may still help someone.
What happened in my case was moc
was generating the moc_ .cpp
files but VC doesn't know that It has to compile them too. So I manually added those moc generated files so that it compiles. and It worked.
I faced the same linker error today, but it was due to a small slip:
I added cpp/ui files to my project manually, but forgot to add the header file explicitly as header file. Now when compiling I got a similar error message as above and the moc_*.cpp file(s) were not generated in the debug (or release) directory of the build. That was not such an obvious mistake, qmake did not complain and other than the linker message I got no errors.
So if anyone encounters the same problem again (or makes the same copy & pase mistake): make sure the header files have also been added to your project file
Citate from book "C++ GUI Programming with Qt 4" (page 19): For moc to work correctly, we must put the class definition in a header file, separate from the implementation file. So, you need write 2 files for your class: Multiplication_dialog.h and Multiplication_dialog.cpp! And you must recreate makefile!