What does the Q_OBJECT macro do? Why do all Qt objects need this macro?(Q_OBJECT 宏有什么作用?为什么所有 Qt 对象都需要这个宏?)
问题描述
我刚开始使用 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 文档:
元对象编译器,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 对象都需要这个宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Q_OBJECT 宏有什么作用?为什么所有 Qt 对象都需要这


基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07