Q_OBJECT宏是做什么的?为什么所有的Qt对象都需要这个宏? [英] What does the Q_OBJECT macro do? Why do all Qt objects need this macro?
问题描述
我刚刚开始使用Qt,注意到所有的示例类定义都有 Q_OBJECT
作为第一行。
I just started using Qt and noticed that all the example class definitions have the macro Q_OBJECT
as the first line. What is the purpose of this preprocessor macro?
推荐答案
从 Qt文档:
Meta-Object编译器moc是
程序处理Qt的C ++
扩展。
The Meta-Object Compiler, moc, is the program that handles Qt's C++ extensions.
moc工具读取一个C ++头文件。
如果找到一个或多个包含Q_OBJECT
宏的类
声明,它将生成一个C ++源文件
,其中包含
的元对象代码。其中,
元对象代码是
信号和槽机制,
运行时类型信息和
动态属性系统所需要的。
The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system.
这篇关于Q_OBJECT宏是做什么的?为什么所有的Qt对象都需要这个宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!