Qt: SIGNAL, SLOT 宏声明 [英] Qt: SIGNAL, SLOT Macro declaration

查看:85
本文介绍了Qt: SIGNAL, SLOT 宏声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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.

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

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.

推荐答案

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

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

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

#a(带有 #a 字符串化运算符) 将简单地将括号内的任何内容转换为字符串文字,以根据提供给宏的签名创建名称.1"和2"只是为了区分插槽和信号.

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.

如果您想知道为什么?"在所有这些宏内容和预处理中,我建议您阅读Meta-对象编译器"或 MOC.为了好玩,您可以看看 MOC 对您提供的代码做了什么.查看它的输出,看看它包含什么.那应该很有用.

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.

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

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)

这篇关于Qt: SIGNAL, SLOT 宏声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆