A set of one-line C++ macros to simplify the creation of reccurent things in Qt projects (like Qt Meta Properties) so that doing them in C++ is not harder than in QML, and requires no boilerplate glue-code.
(Exemples must be added)
- clone or download this repository
- add
include (<path/to/QDefs>/QDefs.pri)in your.pro
-
Q_WRITABLE_***_PROPERTY: a macro that takes a type and a name, and creates automatically the member attribute, the public getter and setter, and the Qt signal for notifier, and allow use in QML by exposing a read/writeQ_PROPERTY. -
Q_READONLY_***_PROPERTY: another macro that does almost the same asQ_WRITABLE_PROPERTYexcept that the property is not modifiable from the QML side, only C++ can access the setter. -
Q_CONSTANT_***_PROPERTY: a simplified version of the previous macros, that exposes a constant property with only a getter, from C++ or QML side. -
Q_ABSTRACT_***_PROPERTY: a simplified version of the previous macros, that exposes a purely virtual constant getter to be override by derrived class.
The *** can be either VAR, PTR, REF, ENU or FUZ. The three first are simple macros that you use by simply passing the non-qualified type (T) and it'll add the qualifiers for var (none), pointer (*), or constant-reference (const &) where needed. The fourth one will do the same as VAR except it will be casted to int in QML -> usefull for properties based on Q_ENUM_CLASS. The fifth one will do the same as VAR except the comparison in the setter will be donne using qFuzzyCompare.
Q_ENUM_CLASS: a macro to declare a "gadget" struct that only contains aQ_ENUMand can be exposed as is to QML. It can be used with very similar syntax from both C++ and QML (<Name>::<Key>in C++ vs<Name>.<Key>in QML/JS).
Q_OBJECT_SINGLETON: a macro that make a Q_OBJECT class singleton (constructor must be declared private manually)
Q_MEASURE_TIME: a macro that wraps arround a method to measure the time it takes to execute
Well, license here is pretty "super-open"