Generating MOC for new QOBJECT files in visual studio 2010

12,877

Solution 1

If your custom classes are not moc'ed automatically, you could have forgotten to add a Q_OBJECT macro in class declarations or to put QObject as the first class that is inherited from in case of multiple inheritance (the order of classes from which your derived class inherits matters). If it's not your case, you may want to read this:

http://truth2.wordpress.com/2010/09/04/custom-build-rules-for-qt-under-visual-studio-2010/

BTW: QT versions have their nuances and thus it is helpful if you inform about which version you use.

Solution 2

I just find a new way of dealing with the "no moc_*.cpp file generated after adding new .h/.cpp file" error.

First, you go to "Solution Explorer -> Right click property page of the new .h file", then change the build to to "Custom Build Tool".

Then, you should find a .h file which has successfully generated "moc_*", and copy all the contents in "Custom Build Tool -> General" to the new .h file setting page.

After that, build your project.

Finally, add the generated "moc_*" file to your project.

Done! Now you can build it as usual.

Share:
12,877
jaykumarark
Author by

jaykumarark

Graphics programmer. Philosophy: Understand nature through computer graphics.

Updated on June 18, 2022

Comments

  • jaykumarark
    jaykumarark almost 2 years

    I created a project using qmake and it automatically generated moc files for classes that inherit QObject either directly or indirectly. However, if I add a new class that inherits the QObject the QT plugin doesn't generate MOC files during the build process. What settings should I tweak so that I can do this automatically each time I add a new QObject file?