Hey guys, I have the following class:
- Now I'm in myInterface::myFunction()
- I want to cast "this" into myWidget:
Code:
qobject_cast<myWidget *> (this);
This doesn't seem to work anyone knows why?
Printable View
Hey guys, I have the following class:
- Now I'm in myInterface::myFunction()
- I want to cast "this" into myWidget:
Code:
qobject_cast<myWidget *> (this);
This doesn't seem to work anyone knows why?
Do you have Q_OBJECT macro in your class?
Let me clarify what I was trying to do:
I have a myAbstractClass supposed to be used like that :
But,
In my library, I'm not defining the myObject class, just the myAstractClass.
It's "supposed" to be used with a QObject all the time to have the benefit of parency. (which is a bad design at this point).
So I wanted to qobject_cast that base class in QObject assuming it was inheriting QObject.
In that "ugly" case I guess dynamic_cast is my only option.
Use Q_DECLARE_INTERFACE in myAbstractClass. Then you'll be able to use object_cast. And remember about Q_OBJECT in the subclass.