PDA

View Full Version : Don't understand Q_OBJECT



Cruz
16th January 2009, 09:14
Hello.

In the tutorials and examples everywhere I see that all class defintions start with the Q_OBJECT macro. I'm using Eclipse with Qt eclipse integration as IDE and rely on the existing functions to create new classes automaticly. None of them have the Q_OBJECT macro inside. So what is this macro about and how come my project still compiles and works right?

Cruz

spirit
16th January 2009, 09:31
it's from Qt Assistant


Q_OBJECT
The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.

radek.z
18th January 2009, 12:57
if you put Q_OBJECT macro in your class declaration, than you tell the the moc (meta-object compiler) to run on this class, so check the moc tool in documentation to see what it does. The main thing it does is to deal with signals and slots. So if you want to use signal and slot in your class then you have to put Q_OBJECT macro there

wysota
19th January 2009, 08:30
So if you want to use signal and slot in your class then you have to put Q_OBJECT macro there

Actually this is not true. You have to place the macro if you want to declare new signals or slots. Using existing ones works fine without the macro.

radek.z
19th January 2009, 12:26
Yeah, that's right. I forgot to write that