Q_OBJECT macro - what exactly does it do?
I'm hoping somebody can give me a summary of what the Q_OBJECT macro really is.
* Is it a C++ macro in the traditional sense. If so, where is it defined, and what exactly does the preprocessor do when it comes accross Q_OBJECT
* Apparently qmake recognizes the Q_OBJECT macro in project source files. So does qmake actually parse the C++ code and identify all the signals and slots in the source code for the class in which Q_OBJECT is included? This would be surprising to me since it would require parsing of C++ syntax.
* What are "signal:" and "slot:"... apparently they are not macros. Does the compiler recognize these things, or does qmake do a trick and modify all the sources so that the compiler doesn't even see these words?
Re: Q_OBJECT macro - what exactly does it do?
Quote:
Originally Posted by
magland
* Is it a C++ macro in the traditional sense. If so, where is it defined, and what exactly does the preprocessor do when it comes accross Q_OBJECT
Yes, it's a macro that expands into a meta-data declaration for a class that contains it. The implementation for methods declared by Q_OBJECT are provided by MOC (take a look at moc_* files).
Quote:
* Apparently qmake recognizes the Q_OBJECT macro in project source files. So does qmake actually parse the C++ code and identify all the signals and slots in the source code for the class in which Q_OBJECT is included? This would be surprising to me since it would require parsing of C++ syntax.
Not exactly. MOC does that :) And it doesn't require C++ syntax parser. It looks for well known tokens (like "signals:" or "slots") and identifies methods declared after them.
Quote:
* What are "signal:" and "slot:"... apparently they are not macros. Does the compiler recognize these things, or does qmake do a trick and modify all the sources so that the compiler doesn't even see these words?
They are empty macros (really aliases for Q_SLOTS and Q_SIGNALS afair) that serve as tags for moc. As they are empty (not quite... I think "ignals" actually expands to "protected" or "private") compiler doesn't even see them as they are substituted by empty strings by the C++ preprocessor.
Edit:
Baaah... forgot the "must-read" link: http://doc.trolltech.com/qq/qq16-dynamicqobject.html
Re: Q_OBJECT macro - what exactly does it do?
Wysota, you are the best :)
Re: Q_OBJECT macro - what exactly does it do?
Quote:
Originally Posted by
magland
Wysota, you are the best :)
No, I'm not :)
Here is another link you might find interesting (Flash 9 required):
http://www.trolltechvideo.com/video/...2_4/video.html