moc_xxxx.cpp 和 xxxx.moc
2013-11-06 23:35
691 查看
用qmake处理moc文件:
qmake产生moc_xxxx.cpp并将其编译为可链接的moc_xxxx.o。在某些特定的情况下,可能比较好的用法是先产生moc_xxxx.cpp而不将其编译为*.o文件,然后moc_xxxx.cpp可以通过在xxxx.cpp中添加#include "moc_xxxx.cpp"方式被include。
stackoverflow上的说明:
http://stackoverflow.com/questions/5854626/qt-signals-and-slots-error-undefined-reference-to-vtable-for
Whenever you declare a QObject inside a filename.cpp file, you should add #include "filename.moc" to the end of your .cpp file and qmake will do the right thing for you. This is the common practice in KDE, for example.
关于moc_xxxx.cpp 和 xxxx.moc的产生:
when you declare a QObject class in a header file xxxx.h generated
file is moc_xxxx.cppwhen you declare a QObject class in a source file xxxx.cpp
generated file is xxxx.moc because
if you declare a QObject class in xxxx.h and another in xxxx.cpp the two generated files can not have the same name
它编译是是需要这个文件的,作为库提供给用户使用,不包含它的话用户工程中也会自动生成包含它,这不符封装规则,库的事情库自己应完成。如果库里使用了名字空间,更是这样,用户处理的话(实际上是qmake编译器帮完成的)就可能不知道名字空间从而产生问题。
qmake产生moc_xxxx.cpp并将其编译为可链接的moc_xxxx.o。在某些特定的情况下,可能比较好的用法是先产生moc_xxxx.cpp而不将其编译为*.o文件,然后moc_xxxx.cpp可以通过在xxxx.cpp中添加#include "moc_xxxx.cpp"方式被include。
stackoverflow上的说明:
http://stackoverflow.com/questions/5854626/qt-signals-and-slots-error-undefined-reference-to-vtable-for
Whenever you declare a QObject inside a filename.cpp file, you should add #include "filename.moc" to the end of your .cpp file and qmake will do the right thing for you. This is the common practice in KDE, for example.
关于moc_xxxx.cpp 和 xxxx.moc的产生:
when you declare a QObject class in a header file xxxx.h generated
file is moc_xxxx.cppwhen you declare a QObject class in a source file xxxx.cpp
generated file is xxxx.moc because
if you declare a QObject class in xxxx.h and another in xxxx.cpp the two generated files can not have the same name
它编译是是需要这个文件的,作为库提供给用户使用,不包含它的话用户工程中也会自动生成包含它,这不符封装规则,库的事情库自己应完成。如果库里使用了名字空间,更是这样,用户处理的话(实际上是qmake编译器帮完成的)就可能不知道名字空间从而产生问题。
相关文章推荐
- vs2010下的moc_XXXX.cpp文件
- Qt中moc问题(qt moc 处理 cpp)
- Qt5+vs2015无法打开源文件moc_XXX.h/cpp的问题
- Qt中moc问题(qt moc 处理 cpp)
- error prj0019 running moc on "XXXX.h"
- moc_xxx No Such file or directory.cpp
- Qt中moc问题(qt moc 处理 cpp)
- vs2010中moc文件生成方法,qt找不到moc_**.cpp
- QT中出现的 undefined identifier 'Ui' Specified file '/Symbian/Carbide/workspace//moc_.cpp' not found等问题解决
- 编译出现警告Makefile.Release:122: 警告:overriding commands for target `temp/moc/moc_frmcalibrationtool.cpp'
- :-1: error: [debug/moc_gotocelldialog.cpp] Error 2
- Parse Too complex in xxxx.cpp --------source insight
- Qt中moc问题(qt moc 处理 cpp)
- VS下Qt生成ui_xxx.h和moc_xxx.cpp的路径设置
- Qt中moc问题(qt moc 处理 cpp)
- vs2010+QT 中添加mocXXX.cpp
- VS2013中添加继承自Qt的类时提示没有moc_xxx.cpp
- moc处理cpp文件
- moc处理cpp文件
- Qt Error: moc_*.cpp error