hi there. I have a base class "Shape" where I derive other classes like "Circle", "Square" "Rectangle" etc. Now I have a function that takeS one parameter of type "Shape" and then within the function I have to get the name of the class that was passed to the function and I am getting the class name through QMetaObject. This is how I get the class name:
QString getClassName
(Shape
* shapeObj
){ return meta->className();
}
QString getClassName(Shape* shapeObj){
const QMetaObject meta = shapeObj->QMetaObject();
return meta->className();
}
To copy to clipboard, switch view to plain text mode
Outside the function I have instantiated two instances of "Shape" in the following manner:
Shape* circleObj = new Circle();
Shape* squareObj = new Square();
Shape* circleObj = new Circle();
Shape* squareObj = new Square();
To copy to clipboard, switch view to plain text mode
After that I pass these objects to my function
void getClassName(Shape* shapeObj)
void getClassName(Shape* shapeObj)
To copy to clipboard, switch view to plain text mode
. This function is suppose to get the class name of a passed object. for exmple: If i pass the object "circleObj" to the function the function must return the class name "Circle" but instead the function always returns the base class name "Shape".
HOW CAN I FIX THIS?
Bookmarks