I came across curious behavior in QT.
Lets say you have a base controller:
class BaseController : public QObject
{
Q_OBJECT
public:
BaseController() = default
protected:
inline BaseNode * getRoot() const noexcept { return root; }
protected:
BaseNode * root;
};
And ExtraController:
class ExtraController final : public BaseController
{
Q_OBJECT
Q_PROPERTY( BaseNode * root READ getRoot NOTIFY changed )
public:
ExtraController() { root = new ExtraNode(); }
signals:
void changed();
};
Key moment, there is a two type of nodes. BaseNode simply an abstract class with property "id". ExtraNode is heir of BaseNode and has property "name".
Inside qml I use something like:
Label {
text: extraController.root.name // property root - calls getRoot() in BaseController
}
And its works! Despite the fact that function getRoot() of a BaseController returns pointer to a BaseNode, which doesn't have "name" property. Question is: How does it work? How can I use properties of derived class in qml? Does qt perform dynamic_cast or so?