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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With