Why is important to include “.moc” file at end of a Qt Source code file?
Why is it important to add an include for .moc file in a Qt cpp source code? This is a common step used in several Qt samples, including this one: http://doc.qt.io/qt-5/qttestlib-tutorial1-example.html ; where the line #include "testqstring.moc" should be included in the end of the file. I don't understand exactly why this is necessary. Thanks. It's necessary if you define QObject subclasses with the Q_OBJECT macro in a .cpp file. When you do so: qmake must generate rules inside your Makefile to invoke moc on that .cpp file. That special (hackish?) inclusion triggers qmake to do so, and tells