Q_OBJECT 宏和元对象代码
此链接:http://doc.trolltech.com/4.5/moc.html#moc< /a> 说
moc 工具读取 C++ 头文件。 如果找到一个或多个类 包含 Q_OBJECT 的声明 宏,它生成一个 C++ 源文件 包含元对象代码 这些课程。
什么是元目标代码?
编辑1
如何知道我应该在哪些类中编写 Q_OBJECT?一个例子是信号和槽,还有其他需要使用它的情况吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以阅读文章 Qt 内部结构和逆向 深入了解Qt 及其 moc 编译器(元对象编译器)。总之,元对象是由 Qt 的 moc 编译器创建的,用于向类添加额外的信息,如信号/槽机制等。
You can read the article Qt internals and Reversing to get in depth knowledge about Qt and its moc compiler (meta objet compiler). In summary a meta object is created by Qt's moc compiler to add extra information to a class like signal/slot mechanism etc.
元对象通过创建新对象或操作现有对象来增强编程语言。它们提供了语言本身实际上不具备的功能。元对象由编译时或运行时解释。在 Qt 和 C++ 中,它是在编译时由元对象编译器 (moc) 完成的。
一个示例案例是信号/时隙概念的使用。
Meta objects enhance programming languages by creating new or manipulate existing objects. They provide functionalities a language does not actually have by itself. The Meta Objects are interpreted either by compile time or run time. In Qt and C++ it is done during compile time by the Meta Object Compiler (moc).
An example case is the usage of the signal/slot concept.
Qt 环境中的元对象代码是一个 C++ 源文件,它是放置 Q_OBJECT(和/或其他相关宏)的 C++ 源文件的扩展版本。元对象代码将包含您的实现以及一些其他额外的(元)代码,以便信号和槽机制工作。
A meta object code in Qt environment is a C++ source file that is an expanded version of the C++ source file where you've put Q_OBJECT (and/or other related macros). The meta object code will have your implementation plus some other extra (meta) code so that signal and slots mechanism work.
元对象包含有关对象的元信息,例如其名称及其信号和槽的文本描述。这使得通过“名称”调用信号成为可能。请参阅有关 QMetaObject 和此 文章。
A meta-object contains meta-information about an object like its name and a textual description of its signals and slots. This make it possible to call signal by "name". See the documentation about QMetaObject and this article.