Qt:SIGNAL、SLOT 宏声明
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Neil 所说,SLOT 和 SIGNAL 宏被定义为
#a (带有 # a 字符串化运算符)将简单地将括号内的内容转换为字符串文字,以根据提供给宏。 “1”和“2”仅用于区分时隙和信号。
这篇较早的文章应该可以为您提供更多见解。
如果您想知道“为什么?”关于所有这些宏内容和预处理,我建议您阅读“元对象-编译器”或MOC。为了好玩,您可以看看 MOC 对您提供的代码做了什么。查看其输出并查看其中包含的内容。这应该是非常有用的信息。
简而言之,通过 MOC 进行的这种预处理允许 Qt 实现 C++ 未作为标准提供的一些功能(如信号和槽)。 (尽管可以说这个概念有一些与 Qt 无关的实现,它们不需要元对象编译器)
As Neil said, the SLOT and SIGNAL macros are defined as
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)