I am trying to write a wrapper to some data that will be held in a container. This data is going to be interfacing with QML, and henceforth will have Q_PROPERTIES in it. However, I want this data to be derived from a specific base class, so I can call overridden methods without having to cast. Here is an example.
class Base : public QObject
{
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
public:
/*implementation is irrelevant, just boilerplate code*/
}
class BaseBool : public Base {
Q_PROPERTY(bool value READ value WRITE setValue NOTIFY valueChanged)
public:
/*I want to override the functions here so I can just call them
like I would for a base class, but I want them to be different types.
I want to extend this for other types too.*/
}
Hopefully this makes sense. Obviously something templating the class and have a Q_PROPERTY of type T would be ideal, however that is not possible with current Qt. Are there any decent solutions for this? There might be better design patterns that address this, but I am at a loss right now.