问题描述
我使用 qmake 创建了一个项目,它自动为直接或间接继承 QObject 的类生成了 moc 文件.但是,如果我添加一个继承 QObject 的新类,则 QT 插件在构建过程中不会生成 MOC 文件.我应该调整哪些设置,以便每次添加新的 QObject 文件时都可以自动执行此操作?
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?
推荐答案
如果您的自定义类没有自动被移动,您可能忘记在类声明中添加 Q_OBJECT 宏或将 QObject 作为第一个类在多重继承的情况下继承(您的派生类继承的类的顺序很重要).如果不是您的情况,您可能需要阅读以下内容:
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/
顺便说一句:QT 版本有其细微差别,因此如果您告知您使用的是哪个版本会很有帮助.
BTW: QT versions have their nuances and thus it is helpful if you inform about which version you use.
这篇关于在 Visual Studio 2010 中为新的 QOBJECT 文件生成 MOC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!