> > Hi all, > > I have found a little project which I found very nice to use especially if > you want expose you C++ class to QML. > Take a look at this project developed by Thomas Boutroue > http://gitlab.unique-conception.org/qt-qml-tricks/qt-supermacros > and > http://gitlab.unique-conception.org/qt-qml-tricks/qt-qml-models > > Here is the link to the Lightning Talk he had at QtWS15 in Berlin. > https://www.youtube.com/watch?v=96XAaH97XYo > > I use this tools in my Qt/QML application, and it saves me so much time! > > Regards > > Fabrice >
I've used those and personnal macros before but I've since stopped from doing it. At first it's useful but then you need for example a property that's computed from another one, or some special case properties. Should I create a specific macro for this case used once or twice in the project, or should I use a normal Q_PROPERTY and have a weird mix of non-Qt macros and Q_PROPERTY, making your code less readable? Sometimes l also want to set a breakpoint in a getter or setter, macros don't help for that. > Q_PROPERTY_RWN(proptype, arg) --> Q_PROPERTY(proptype arg READ arg WRITE setArg NOTIFY argChanged) Qt Creator makes it easy to write Q_PROPERTY with its snippets. You can type Q_PROPERTY <ctrl-space> type <tab> name <return> and it will generate Q_PROPERTY(type name READ name WRITE setName NOTIFY nameChanged) You can add your own custom snippets if you want constant or non writable properties. The only gripe I have with Qt Creator regarding properties is its Q_PROPERTY refactoring. * It adds setters as slots ( https://bugreports.qt.io/browse/QTCREATORBUG-15779 ) * Non scalar types like QString are passed as value to the property setter ( whereas if you create a QString member variable and you do Refactor / Create Setter Member Function, the QString is passed as a const ref) * Notify signals have parameters That means that when I refactor a Q_PROPERTY to add missing members, I have to do a second manual pass where I : 1 - Remove the signal parameter in the signal declaration and remove it in the setter definition 2 - Move the setter from the public slots to under the getter 3 - Refactor move their definition to the .cpp 4 - Remove the useless added new lines. Regards, Pierre-Yves
_______________________________________________ Interest mailing list [email protected] https://lists.qt-project.org/listinfo/interest
