Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating MOC for new QOBJECT files in visual studio 2010

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?

like image 462
jaykumarark Avatar asked Dec 25 '22 08:12

jaykumarark


2 Answers

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.

like image 69
KjMag Avatar answered Dec 28 '22 11:12

KjMag


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.

like image 37
Alan Avatar answered Dec 28 '22 11:12

Alan