QMetaObject questions
-
Hi
Say I have a method that takes a point to a base class and I provide this method with a pointer to a class derived from the base.
Now, I want to use QMetaObject to get the class namevoid myMethod(Base* ptr) { QString s = ptr->metaObject()->className(); }
class name is always Base
Is there a wayuof getting the derived class name?
Thanks
-
Hi,
Can you show the declaration of your Base and Derived classes ?
-
Hi,
@GrahamL said:
class name is always Base
Add the
Q_OBJECT
macro to your derived class: http://doc.qt.io/qt-5/qobject.html#Q_OBJECTThen, run qmake again and recompile your program.