Search code examples
c++qttype-conversionconstantsqobject

Convert const QObject* to QObject*


I am quite new to Qt. Let MyClass be a sub-class of QObject.

Is there a way to convert properly a const MyClass * object to a MyClass * object?

I wanted to create a constructor MyClass(const MyClass *object); but it doesn't seem to be recommended.


Solution

  • Use the following code :

     MyClass *objRef = const_cast<MyClass *>(obj);