Why not making a macro?
#define Q_PROPERTY_WITH_ACCESSORS(name, type, getter, setter) private: type _##name; public: Q_PROPERTY(type name READ getter WRITE setter) type const& getter () const { return _##name; } void setter (type const &v) { _##name = v; }
#define Q_PROPERTY_WITH_ACCESSORS(name, type, getter, setter) private: type _##name; public: Q_PROPERTY(type name READ getter WRITE setter) type const& getter () const { return _##name; } void setter (type const &v) { _##name = v; }
To copy to clipboard, switch view to plain text mode
This macro will take 4 arguments:
- Property's name,
- Property's type,
- Getter name,
- Setter name.
For example, you can call it where you would call Q_PROPERTY like that:
Q_PROPERTY_WITH_ACCESSORS
(toto,
QString, toto, setToto
)
Q_PROPERTY_WITH_ACCESSORS(toto, QString, toto, setToto)
To copy to clipboard, switch view to plain text mode
It will generate a property named "toto" of type QString, reader "toto", setter "setToto", private member named "_toto".
i did not test what would be the moc'ing result of that (Does MOC expands macros before processing?...) as i just invented it.
Pierre.
Bookmarks