5

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.

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • Have you looked at this thread: http://stackoverflow.com/questions/1368593/qt-question-how-do-signals-and-slots-work It contains some interesting links and information. – Bart May 04 '11 at 08:42
  • 1
    See http://stackoverflow.com/questions/1815172/is-it-possible-to-see-definition-of-q-signals-q-slot-slot-signal-macros – Neil G May 04 '11 at 08:43
  • 2
    The basics: http://doc.qt.nokia.com/4.7/signalsandslots.html – Michael Burr May 04 '11 at 08:49
  • @Neil Thank for the link, it made me find this: http://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2-browser/d1/db2/src_2corelib_2kernel_2qobjectdefs_8h.html It is the first time that I didn't look at the the similar threads listed while forming the question, it is my fault :( Now if you could put this as an answer below, I'll select it :) – Aquarius_Girl May 04 '11 at 08:55
  • @Bart @Michael that classic signalsandslots link was already known to me, but it doesn't say anything regarding the macro definitions. – Aquarius_Girl May 04 '11 at 08:56
  • 2
    To your edit: They are simple macros. The #a means that the a in the parentheses of SLOT will be made into a string. (this # is sometimes referred to as the "Stringizing Operator"...yeah...) The "1" and "2" for slots and signals respectively are merely to distinguish between the two. The first response here gives you some further explanation: http://stackoverflow.com/questions/2008033/how-does-qt-implement-signals-and-slots – Bart May 04 '11 at 09:19
  • 2
    If you're wondering about the "why" of all this macro stuff with Qt, you might want to read up on the "Meta-Object-Compiler" (MOC). And for the fun of it, just read to the output of MOC and see what it does to your code. That should provide you some insight. – Bart May 04 '11 at 09:27
  • 1
    I hesitated to do that because I merely provided links to other posts already on SO and would have to quote an answer from @Neil in my answer. But as per your request I have done so. – Bart May 04 '11 at 09:41

1 Answers1

21

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)

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
Bart
  • 19,692
  • 7
  • 68
  • 77