[Solved] QMetaObject::className for derived type
-
wrote on 2 Aug 2011, 10:26 last edited by
Hello
I have the following situation. I have a base class called ABase which derives from QObject and I have several classes which derives from ABase. now I want to get type name of those classes derived from ABase. For this, I tried obj.metaObject()->className(), but it returns the name of ABase, not of the derived class. So my question is, is there a way to get type name of the derived class?
I know Q_CLASSINFO macro is a solution, I can name all classes, but I want to avoid that.Thanks
-
wrote on 2 Aug 2011, 10:31 last edited by
Allright guys, I found the solution. Just add Q_OBJECT macro in the derived class and that should work :)
-
wrote on 2 Aug 2011, 10:32 last edited by
Thanks for posting your solution Davita :)
-
wrote on 2 Aug 2011, 11:32 last edited by
Hi Davita,
metaObject->className returns the calls name from the meta object. The meta object is only created, if Q_OBJECT macro is set in the classes header and the MOC compiler created the moc file.
1/4