qt - Behaviour of QMetaObject within a base class constructor -
i have simple qobject-derived object:
class myobject : public qobject { q_object public: myobject(qobject* parent = 0); }; myobject::myobject(qobject* parent) : qobject(parent) { std::cout<<"[base] "<<this->metaobject()->classname()<<std::endl; }
and further derive object:
class myderivedobject : public myobject { q_object public: myderivedobject(qobject* parent); }; myderivedobject::myderivedobject(qobject* parent) : myobject(parent) { std::cout<<"[derived] "<<this->metaobject()->classname()<<std::endl; }
whenever instantiate class, following output:
myderivedobject y; ## output ### [base] myobject [derived] myderivedobject
i don't it. since inheritance hierarchy myderivedobject
-> myobject
-> qobject, both have same instance of qobject parent (right?). know of run-time type information provided via moc, shouldn't change fact once static_cast<qobject*>(/*mysomeobject*/)
on pointer 1 of objects, same thing (even in memory) long qobject functionality concerned. why different return values of classname()
? either ways, how obtain name of type qobject of?
i not sure details each qobject-derived class has own copy of meta object structure:
myderivedobject y; qdebug() << (void*) y.metaobject(); qdebug() << (void*) y.myobject::metaobject();
that gets 2 different pointers meta object.
edit: not sure second question is. if want know if qobject derived given class name, use qobject::inherits() find out.
Comments
Post a Comment