[Interest] Better Q_PROPERTY() ?

Jason H jhihn at gmx.com
Thu Dec 6 18:15:17 CET 2018


How, where? I flipped through the menus, and I didn't see anything that looked relevant.

When creating a class that includes Q_OBJECT, I am not prompted for property.
When I context menu a class, I don't get an "Add Properties..." like in Eclipse.

Thanks


> Sent: Wednesday, December 05, 2018 at 12:14 PM
> From: "Vlad Stelmahovsky" <vladstelmahovsky at gmail.com>
> To: interest at lists.qt-project.org
> Subject: Re: [Interest] Better Q_PROPERTY() ?
>
> use QtCreator, so you can autogenerate most of the code there
> 
> On 12/5/18 5:41 PM, Jason H wrote:
> > I've been doing a lot of Q_PROPERTY stuff again, and I waste too much time writing boiler plate code. Last time, I was reminded of the MEMBER modifier, which is what I thought I wanted. But after having worked with it some more, it's not what I want.
> >
> > Given:
> > Q_PROPERTY (qreal scale READ scale WRITE setScale NOTIFY scaleChanged)  // What I end up writing
> > Q_PROPERTY (qreal scale MEMBER _scale NOTIFY) // What I want to write
> >
> > I want the member form to also declare/implement:
> > public:
> > qreal scale() { return _scale; }
> > void setScale(qreal scale) { if (scale != scale) { _scale = scale; emit scaleChanged(scale); } }
> > signal:
> > void scaleChanged(qreal scale);
> >
> > Where T=type, N=name M=member
> > public:
> > T N() { return M; }
> > void setN(T N) { if (M != N) { M = N; emit NChanged(N); } }
> > signal:
> > void NChanged(T N);
> >
> > I'm trying to think of how to do this, and this seems doable:
> >
> > class X {
> >
> > ...
> > INCLUDE_AUTOMOC_DECLARATIONS
> > };
> >
> > Where
> > INCLUDE_AUTOMOC_DECLARATIONS expands to:
> > #include "filename_X_automoc.h"
> >
> > Where MOC has written the declarations. Similarly, there can be one for implementations as well.
> >
> > Ideally though, all I should need to write:
> > Q_PROPERTY (qreal scale NOTIFY)
> >
> > Epanding to:
> > private:
> > T _N;
> > public:
> > T N() { return _N; }
> > void setN(T N) { if (_N != N) { M = N; emit NChanged(N); } }
> > signal:
> > void NChanged(T N);
> >
> > I know this might sound trivial but if I'm making 5 classes each with 10 properties, that's 1500 lines of boilerplate code that I'm writing (with code style applied).
> >
> > Is there any way to get closer to my ideal?
> > _______________________________________________
> > Interest mailing list
> > Interest at lists.qt-project.org
> > https://lists.qt-project.org/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at lists.qt-project.org
> https://lists.qt-project.org/listinfo/interest
> 



More information about the Interest mailing list