[Interest] using a custom class as parameter of signal/slot, used in QML

Sylvain Pointeau sylvain.pointeau at gmail.com
Sat Mar 2 10:41:40 CET 2019


Hello Again,

I just saw on stackoverflow that it is possible with a Q_GADGET, I tried
and it works as expected. That's good, seems it appeared in Qt 5.5.
(Just missing now the auto completion from Qt Creator on the QML side for
Q_GADGET objects)

I honestly tried this one as well without success, I just found out it is
because I did qmlRegisterType on this type which is obviously incorrect I
recognise it
I learn the hard way - but is there other ways? :-)

https://stackoverflow.com/questions/31433260/passing-q-gadget-as-signal-parameter-from-c-to-qml

Best regards,
Sylvain

On Fri, Mar 1, 2019 at 11:00 PM Jérôme Godbout <godboutj at amotus.ca> wrote:

> You can also give CBor implementation a look,maybe it could fit your bill
> too:
>
>
>
> https://doc.qt.io/qt-5/qcbormap.html
>
>
>
>
>
> *From:* Sylvain Pointeau <sylvain.pointeau at gmail.com>
> *Sent:* March 1, 2019 4:46 PM
> *To:* Jérôme Godbout <godboutj at amotus.ca>
> *Cc:* Qt Project <interest at qt-project.org>
> *Subject:* Re: [Interest] using a custom class as parameter of
> signal/slot, used in QML
>
>
>
> On Fri, Mar 1, 2019 at 10:29 PM Jérôme Godbout <godboutj at amotus.ca> wrote:
>
> Why is the struct deleted one the signal is finished? You create a
> structure only for the signal? it’s not an object or data that will outlive
> that call in the end? If so, you really need to make a copiable
> representation of the struct.
>
>
>
> Yes it is just an object created for the time of the signal, to avoid
> having 5 parameters to my signal.
>
>
>
>
>
> What kind of data live into your struct? are they all basic type or
> pointer? or do you have QObject into it?
>
> QVariantMap seem like an easy way out.
>
>
>
> it is (for now) just integers, I just tried QVariantMap (just after my
> previous email), I find it good enough, I will stay with this I think.
>
>
>
> JSON serialization or even better QDataStream (which is really fast
> compare to JSON) could help you do it. You could do an operator<<() and
> operator>>() with QDataStream on your struct to do it. QByteArray are
> copiable.
>
>
>
> If you can provide more information about your struct data that could help.
>
>
>
> it is just basic data for now.
>
>
>
> But I would really wish that Qt could do that for us so I can just keep on
> using my structure.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190302/1c324384/attachment.html>


More information about the Interest mailing list