Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: SIGNAL, SLOT Macro declaration [duplicate]

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.

like image 792
Aquarius_Girl Avatar asked Nov 29 '22 16:11

Aquarius_Girl


1 Answers

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)

like image 56
Bart Avatar answered Dec 05 '22 17:12

Bart