PDA

View Full Version : what is the Difference between these class declaration ?



namus
30th June 2010, 13:52
What the difference in declaring Q_OBJECT in class & inheriting public QObject ?




class VerboseObject {

Q_OBJECT

public:
VerboseObject(QObject *parent, const QString& name):QObject(parent)
{}
~VerboseObject() {}

};

&

class VerboseObject : public QObject {

public:
VerboseObject(QObject *parent, const QString& name):QObject(parent)
{}
~VerboseObject() {}

};

tbscope
30th June 2010, 14:17
class VerboseObject {

Q_OBJECT

public:
VerboseObject(QObject *parent, const QString& name):QObject(parent)
{}
~VerboseObject() {}

};
You probably made a mistake when writing the code here, but this is wrong. Your class definition doesn't say that VerboseObject subclasses QObject (you do say it in the implementation though)
You can not use the Q_OBJECT macro without subclassing QObject.

The Q_OBJECT macro allows you to use signals and slots in your subclass.
It's all in the documentation: http://doc.qt.nokia.com/4.6/qobject.html#Q_OBJECT



class VerboseObject : public QObject {

public:
VerboseObject(QObject *parent, const QString& name):QObject(parent)
{}
~VerboseObject() {}

};


Here you will not be able to use signals and slots.

high_flyer
30th June 2010, 14:18
The doc is your friend:
http://doc.trolltech.com/4.6/metaobjects.html

EDIT: beat to it by previous poster.