How to get class name from a class ?
-
I want to test a object type in a function, the function is passed QAbstractButton *, in the function I can get the class type using:
QString strType(pobjButton->metaObject()->className());
strType is either clsQtRadioButton or clsQtPushButton these are my derived class names.
Is there a way to get a string from the class itself without using an instance? Something like:
QString strClassName(clsQtRadioButton::metaObject()->className());
I know the above won't work as metaObject() can only be used on an instance.
-
What's wrong with qobject_cast<> (or dynamic_cast<> in plain c++) as already explained to you in your previous (basic c++) question?
-
What's wrong with qobject_cast<> (or dynamic_cast<> in plain c++) as already explained to you in your previous (basic c++) question?
@Christian-Ehrlicher , this isn't a cast question, I intend to have a test for the class name then assign a pointer to get a common node pointer from the class.
-
@Christian-Ehrlicher , this isn't a cast question, I intend to have a test for the class name then assign a pointer to get a common node pointer from the class.
@SPlatten said in How to get class name from a class ?:
I intend to have a test for the class name then assign a pointer to get a common node pointer from the class.
And why does dynamic_cast or qobject_cast does not work for this usecase?
-
@SPlatten said in How to get class name from a class ?:
I intend to have a test for the class name then assign a pointer to get a common node pointer from the class.
And why does dynamic_cast or qobject_cast does not work for this usecase?
@Christian-Ehrlicher , ok, that will work, just didn't think of it immediately.