[Solved] QMetaObject::className for derived type
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.
Allright guys, I found the solution. Just add Q_OBJECT macro in the derived class and that should work :)
Thanks for posting your solution 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.