symsahoo
14th August 2008, 06:01
Hi,
I was just trying to understand the concept behind qobject_cast and have landed in to some dilemma :confused:. I would be more than happy if some one could tell me the difference between the two representation of the same logic. I am here by trying to expand the q_object macro to see how it is using the meta object for dynamic identification of the object type.
Preconditions
----------------
I have a QObject subclass,
class QMyTestClass : public QObject
{
Q_OBJECT
public:
QMyTestClass(){}
int Get(){return 23;}
};
QObject *n ;
QMyTestClass *o
First
-----
//QMyTestClass
QMyTestClass* l = reinterpret_cast<QMyTestClass*>(0);
const QMetaObject m = l->staticMetaObject;
n = m.cast(myptr);
o = static_cast<QMyTestClass*> (n);
Second
---------
n = reinterpret_cast<QMyTestClass*>(0)->staticMetaObject.cast(myptr);
o = static_cast<QMyTestClass*>(n);
In the first scenario I am getting the cast as NULL (i.e. o = NULL) where as in the second case I am getting the same as the correct cast. Just wondering what's the difference.
Regards,
Subhransu
I was just trying to understand the concept behind qobject_cast and have landed in to some dilemma :confused:. I would be more than happy if some one could tell me the difference between the two representation of the same logic. I am here by trying to expand the q_object macro to see how it is using the meta object for dynamic identification of the object type.
Preconditions
----------------
I have a QObject subclass,
class QMyTestClass : public QObject
{
Q_OBJECT
public:
QMyTestClass(){}
int Get(){return 23;}
};
QObject *n ;
QMyTestClass *o
First
-----
//QMyTestClass
QMyTestClass* l = reinterpret_cast<QMyTestClass*>(0);
const QMetaObject m = l->staticMetaObject;
n = m.cast(myptr);
o = static_cast<QMyTestClass*> (n);
Second
---------
n = reinterpret_cast<QMyTestClass*>(0)->staticMetaObject.cast(myptr);
o = static_cast<QMyTestClass*>(n);
In the first scenario I am getting the cast as NULL (i.e. o = NULL) where as in the second case I am getting the same as the correct cast. Just wondering what's the difference.
Regards,
Subhransu