Qt:SIGNAL、SLOT 宏声明

发布于 2024-11-04 19:44:46 字数 747 浏览 1 评论 0原文

可能的重复:
是否可以看到 Q_SIGNALS、Q_SLOT、SLOT()、SIGNAL() 宏的定义吗? (Qt)

我在 Google 上找不到 Qt 中宏 SIGNAL 和 SLOT 的声明。

当我们说,connect(button1, SIGNAL(clicked())), this, SLOT(slotButton1()));

我想明白了,突出显示的宏接受哪些各种参数?

任何指向文档的链接将不胜感激。

链接 我通过下面的 Neil 评论说:#define SLOT(a) "1"#a 这里的 a 代表什么?它没有显示在该链接中。

Possible Duplicate:
Is it possible to see definition of Q_SIGNALS, Q_SLOT, SLOT(), SIGNAL() macros? (Qt)

I couldn't find on Google, the declaration of the macros, SIGNAL and SLOT, in Qt.

When we say, connect(button1, SIGNAL(clicked()), this, SLOT(slotButton1()));

I would like to understand, which all kinds of parameters does the highlighted macros accept?

Any link to doc would be appreciated.

The link I got through Neil's comment below says: #define SLOT(a) "1"#a and what does a represent here? It is not shown in that link.

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

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

发布评论

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

评论(1

屋顶上的小猫咪 2024-11-11 19:44:46

正如 Neil 所说,SLOT 和 SIGNAL 宏被定义为

#define SLOT(a) "1"#a
#define SIGNAL(a) "2"#a

#a (带有 # a 字符串化运算符)将简单地将括号内的内容转换为字符串文字,以根据提供给宏。 “1”和“2”仅用于区分时隙和信号。

这篇较早的文章应该可以为您提供更多见解。

如果您想知道“为什么?”关于所有这些宏内容和预处理,我建议您阅读“元对象-编译器”或MOC。为了好玩,您可以看看 MOC 对您提供的代码做了什么。查看其输出并查看其中包含的内容。这应该是非常有用的信息。

简而言之,通过 MOC 进行的这种预处理允许 Qt 实现 C++ 未作为标准提供的一些功能(如信号和槽)。 (尽管可以说这个概念有一些与 Qt 无关的实现,它们不需要元对象编译器)

As Neil said, the SLOT and SIGNAL macros are defined as

#define SLOT(a) "1"#a
#define SIGNAL(a) "2"#a

The #a (with # a stringizing operator) will simply turn whatever is put within the parentheses into a string literal, to create names from the signatures provided to the macros. The "1" and "2" are merely there to distinguish between slots and signals.

This earlier post should provide you some more insight.

If you wonder about the "why?" of all this macro stuff and preprocessing, I would suggest you read up on the "Meta-Object-Compiler" or MOC. And just for fun you could have a look at what MOC does to the code you provide it with. Look through its output and see what it contains. That should be quite informative.

In short, this preprocessing through MOC allows Qt to implement some features (like the signals and slots) which C++ does not provide as standard. (Although there are arguably some implementations of this concept, not related to Qt, which don't require a Meta Object Compiler)

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