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 对象都需要这
基础教程推荐
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
