Q_OBJECT 宏和元对象代码

发布于 2024-11-04 08:49:57 字数 389 浏览 7 评论 0 原文

此链接:http://doc.trolltech.com/4.5/moc.html#moc< /a> 说

moc 工具读取 C++ 头文件。 如果找到一个或多个类 包含 Q_OBJECT 的声明 宏,它生成一个 C++ 源文件 包含元对象代码 这些课程。

什么是目标代码?

编辑1

如何知道我应该在哪些类中编写 Q_OBJECT?一个例子是信号和槽,还有其他需要使用它的情况吗?

This link: http://doc.trolltech.com/4.5/moc.html#moc says

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.

What is a meta object code?

EDIT 1

How to know in which classes I should write the Q_OBJECT? One example is the signals and slots, any other cases where that needs to be used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

空城之時有危險 2024-11-11 08:49:57

您可以阅读文章 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.

行至春深 2024-11-11 08:49:57

元对象通过创建新对象或操作现有对象来增强编程语言。它们提供了语言本身实际上不具备的功能。元对象由编译时或运行时解释。在 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.

万劫不复 2024-11-11 08:49:57

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.

素染倾城色 2024-11-11 08:49:57

元对象包含有关对象的元信息,例如其名称及其信号和槽的文本描述。这使得通过“名称”调用信号成为可能。请参阅有关 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文