Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.13.0 RC 3, 5.14.0 RC2, 5.15.0 RC2
-
None
Description
I would like to create templated QObjects. This would allow me to create a Property structure for example. Which is fully compatible with QML without writing getters and setters and signals for each property and binding it over a Q_PROPERTY macro. Which is prone to bugs and also limits the use of all c++ features.
For example: I would like to have something like the following:
template <std::equality_comparable T>
class Property : QObject<Property<T>> {
//Q_OBJECT not required, since we use the "templated QObject"
{{public: }}
T value(){...}
slot:
set(T&& val){...}
signal:
valueChanged();
private:
T [[Qt::Property READ }}{{value}}{{ WRITE }}{{set NOTIFY }}{{valueChanged}}{{]] value_;
// Alternatively:
// #pragma Qt Property }}{{READ }}{{value{{ WRITE }}{{set NOTIFY }}{{valueChanged }}
// }}{{T value_;
};