[Interest] Q_GADGET vs Q_OBJECT
Russell, Matthew
MRussell at neptec.com
Mon Apr 17 15:04:25 CEST 2017
Awesome. That helps. I lost a lot of time mistakenly trying to "keep things simple" by using smart pointers or passing by value in the interim. But yeah, understanding this moving forward will really help.
Thanks
-----Original Message-----
From: Interest [mailto:interest-bounces+mrussell=neptec.com at qt-project.org] On Behalf Of Shawn Rutledge
Sent: Friday, April 14, 2017 10:26 AM
To: interest at qt-project.org
Subject: Re: [Interest] Q_GADGET vs Q_OBJECT
You got an answer on StackOverflow already, but to repeat: he’s right, a QObject is always passed from C++ to QML by pointer, and a Q_GADGET is always passed by value. That means Q_GADGET is only suitable for smallish self-contained classes, because it will always be copied.
> On 13 Apr 2017, at 20:31, Russell, Matthew <MRussell at neptec.com> wrote:
>
> Why can my Q_GADGET be read perfectly in QML (JS) but not my Q_OBJECT?
>
> I created a class, registered it (Q_DECLARE_METATYPE), and then push instances of it into a QVariantMap. If the object is a Q_GADGET my JS can read it perfectly, but when I switch it to a Q_OBJECT, the objects are blank.
>
> I placed some code examples on SO here: http://stackoverflow.com/questions/43398740/qml-can-see-my-q-gadget-but-not-q-object
>
> Basically I’ve narrowed it down to Q_GADGET vs Q_OBJECT, nothing else seems to make any difference. I’d prefer to use Q_OBJECT so that I can use signals and other objects in the QML/JS can bind to them.
>
> Thanks.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
More information about the Interest
mailing list