tags:

views:

152

answers:

2

Hi,

I am using Qt 4.5 in windows XP. I know we have to use Q_OBJECT macro for signal - slot connection mechanism. But besides that, is there are any other reasons to use the Q_OBJECT macro? I recently come to know that for some other meta-object features we require the Q_OBJECT declaration. What are those features beside the Signal-slots? I tried for documentation regarding that but couldn't find anything helpful. Any pointers regarding this are welcome.

+5  A: 

Hello,

You can find all you need to know about when Q_OBJECT macro is needed here:

http://doc.trolltech.com/4.6/metaobjects.html

In resume you need it for signals and slots, to use tr for translation, to retrieve class name in real time from a QObject, to know if it inherits from other class (instrospection) to set properties and to be able to call newInstance.

Hope it helps.

cnebrera
Yeah.. exactly.. thanks..
liaK
You are welcome :)
cnebrera
You don't _need_ it to know whether a given class inherits from another. See Boost traits for a counterexample.
MSalters
Sorry, I should have said you can use it also for instead of you need it for :)
cnebrera
A: 

AFAIK its of use for retreiving meta information (Names of signal slots, vars) and provides support for the ownership tracking of objects. (aka. just do new and pass parents to these objects and they will be disposed deterministically as time of the parent passes by.)

Robert0