8.4 Q_OBJECT and moc: A checklist
来源:互联网 发布:淘宝卖家分类怎么设置 编辑:程序博客网 时间:2024/04/30 09:49
8.4 Q_OBJECT and moc: A checklist
QObject supports features not normally available in C++ objects:
• Signals and Slots ( Section 8.5 )
• MetaObjects, MetaProperties, MetaMethods ( Chapter 12 , “Meta Objects,
Properties, and Reflective Programming”)
• qobject_cast ( Section 12.2 )
Some of these features are only possible through the use of generated code. The
Meta Object Compiler, moc, generates additional functions for each QObject -derived
class that uses the Q_OBJECT macro. Generated code can be found in files with names
moc_filename.cpp .
This means that some errors from the compiler/linker may be confuscated 8 when
moc cannot find or process a class in the project. To help ensure that moc processes
each QObject -derived class in the project, following are some guidelines for writing
C++ code and qmake project files:
• Each class definition should go in its own .h file.
• Its implementation should go in a corresponding .cpp file.
• The header file should be “wrapped” (e.g., with #ifndef ) to avoid multiple
inclusion.
• Each .cpp file should be listed in the SOURCES variable of the project file;
otherwise it will not be compiled.
• Each header file should be listed in the HEADERS variable of the .pro file.
Without this, moc will not preprocess the file.
• The Q_OBJECT macro must appear inside the class definition of each QObject
derived header file so that moc knows to generate code for it.
NOTE
Because each Q_OBJECT macro generates code, it needs to be preprocessed by moc.
moc works under the assumption that you are only deriving from QObject once and, further,
that QObject is the first base class in the list of base classes. If you accidentally inherit from
QObject more than once, or if it is not the first base class in the inheritance list, you may produce
strange errors in the moc-generated code.
8 confusing + obfuscated
8.5 Signals and Slots 275
NOTE
If you define a QObject -derived class, build an application, realize that you need to add
the Q_OBJECT macro to the class definition, and add it after the project was built with an old
Makefile , you must then rerun qmake to update the Makefile .
make is not smart enough to add the moc step on such files to your Makefile otherwise. A
“clean rebuild” does not fix this problem usually. This is an issue that often causes headaches for
inexperienced Qt developers. For more information about this error message, see Section C.3.1.
QObject supports features not normally available in C++ objects:
• Signals and Slots ( Section 8.5 )
• MetaObjects, MetaProperties, MetaMethods ( Chapter 12 , “Meta Objects,
Properties, and Reflective Programming”)
• qobject_cast ( Section 12.2 )
Some of these features are only possible through the use of generated code. The
Meta Object Compiler, moc, generates additional functions for each QObject -derived
class that uses the Q_OBJECT macro. Generated code can be found in files with names
moc_filename.cpp .
This means that some errors from the compiler/linker may be confuscated 8 when
moc cannot find or process a class in the project. To help ensure that moc processes
each QObject -derived class in the project, following are some guidelines for writing
C++ code and qmake project files:
• Each class definition should go in its own .h file.
• Its implementation should go in a corresponding .cpp file.
• The header file should be “wrapped” (e.g., with #ifndef ) to avoid multiple
inclusion.
• Each .cpp file should be listed in the SOURCES variable of the project file;
otherwise it will not be compiled.
• Each header file should be listed in the HEADERS variable of the .pro file.
Without this, moc will not preprocess the file.
• The Q_OBJECT macro must appear inside the class definition of each QObject
derived header file so that moc knows to generate code for it.
NOTE
Because each Q_OBJECT macro generates code, it needs to be preprocessed by moc.
moc works under the assumption that you are only deriving from QObject once and, further,
that QObject is the first base class in the list of base classes. If you accidentally inherit from
QObject more than once, or if it is not the first base class in the inheritance list, you may produce
strange errors in the moc-generated code.
8 confusing + obfuscated
8.5 Signals and Slots 275
NOTE
If you define a QObject -derived class, build an application, realize that you need to add
the Q_OBJECT macro to the class definition, and add it after the project was built with an old
Makefile , you must then rerun qmake to update the Makefile .
make is not smart enough to add the moc step on such files to your Makefile otherwise. A
“clean rebuild” does not fix this problem usually. This is an issue that often causes headaches for
inexperienced Qt developers. For more information about this error message, see Section C.3.1.
0 0
- 8.4 Q_OBJECT and moc: A checklist
- Q_OBJECT
- Q_OBJECT
- VS2010在QT中用moc编译带有Q_OBJECT时所需设置
- Qt元对象系统(二)【根据moc文件解析Q_OBJECT】
- A Security Checklist
- moc
- checklist
- checklist
- checkList
- Saving and Loading the Checklist Items
- A checklist approach to security code reviews
- How to Improve Query Performance - A Checklist
- CHECKLIST TO USE BEFORE SUBMITTING A PAPER TO A JOURNAL
- CHECKLIST TO USE BEFORE SUBMITTING A PAPER TO A JOURNAL
- Factors to Consider and checklist When Selecting Project Team Members
- Sarbanes-Oxley compliance checklist: IT security and SQL audits
- Code Review Checklist and Best practices in Java
- 【索引】索引五种扫描方式至索引范围扫描
- C# 问题集
- 网络数据包中继与bridge 区别
- C语言文件读写
- iOS开发知识001
- 8.4 Q_OBJECT and moc: A checklist
- 下一代 Bootstrap 的 5 个超酷特点
- dubbo的安装与应用
- JSON入门之二:org.json的基本用法
- Test -> 0x01
- vpn相关知识
- 普通GB2312汉字字符转拼音首字母
- 手机页面调用手机摄像头,录像、摄像、上传已有照片,安卓,苹果通用
- 学习笔记:基础正则表达式