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

Sylvain Pointeau sylvain.pointeau at gmail.com
Fri Mar 1 21:26:54 CET 2019


Hello Jerome,

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

> Since signal are not sync all the time but can be async, the argument need
> to be copiable to allow this. So you need to be able to copy the arguments
> on the signals. Therefore the QObject is not copiable, they cannot be
> passed as arguments directly, you need a pointer. The ownership and
> lifetime of that object is up to you, but you need it to live until all
> handler have finish processing the signal (this can be longer then the
> signal emit for queued connection).
>

Not only it can be asynchrone but also multiple "listeners". One consumer
might be QML, one other might be another Object.
The lifetime is simply impossible to predict, and the ownership is really
an issue.

if the copy would have been possible, we could have used a reference
counted object.

If you can easily copy the structure you probably can serialize/deserialize
> it or put it into a QVariant, QVariantList or QVariantMap. That would be
> copiable.
>

Yes, I agree, this is just another mechanism to implement. I just did it in
Json for one object but this is not ideal neither, but workable. (I
hesitate with QVariant)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/3020a1a2/attachment.html>


More information about the Interest mailing list