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

Jérôme Godbout godboutj at amotus.ca
Fri Mar 1 15:34:14 CET 2019


The fact that the QObject is non copiable, is one of the reason it need a pointer (which can be copied). As for the ownership, you can check with the qqmlengine:
https://doc.qt.io/qt-5/qqmlengine.html#objectOwnership

You can change the ownership too with setOwnership(). I for one exposed the methods to Qml so each side can check/set the qobject ownership based on the needs. This is very helpful to debug.
You can use QPointer to have a pointer that will return to null if the qobject get deleted.

Hope this help.

[36E56279]
une compagnie  [cid:image002.jpg at 01D4D011.EF589B50]
RAPPROCHEZ LA DISTANCE

Jérôme Godbout
Développeur Logiciel Sénior /
Senior Software Developer

p: +1 (418) 800-1073 ext.:109

amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>
[cid:image003.png at 01D4D011.EF589B50]<https://www.facebook.com/LesSolutionsAmotus/> [cid:image004.png at 01D4D011.EF589B50] <https://www.linkedin.com/company/amotus-solutions/>  [cid:image005.png at 01D4D011.EF589B50] <https://twitter.com/AmotusSolutions>  [cid:image006.jpg at 01D4D011.EF589B50] <https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>





From: Interest <interest-bounces at qt-project.org> On Behalf Of Sylvain Pointeau
Sent: March 1, 2019 6:44 AM
To: Qt Project <interest at qt-project.org>
Subject: [Interest] using a custom class as parameter of signal/slot, used in QML

Dear all,

I understood how to use a struct / simple class as a parameter of a signal / slot, and it works well by value.

However as soon as we have to declare the type for QML, it is not good anymore.
It seems that it must be derived from QObject and passed by pointer.

Do I understand well that the QML world does only accept pointers on QObject?

However I don't understand, who owns the pointer of the custom class (derived from QObject) and who actually deletes it?
(I tried a sharepointer but QML does not know how to handle it)

Do you have any idea?

Best regards,
Sylvain


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 6751 bytes
Desc: image001.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 1016 bytes
Desc: image002.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 483 bytes
Desc: image003.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 506 bytes
Desc: image004.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 500 bytes
Desc: image005.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.jpg
Type: image/jpeg
Size: 713 bytes
Desc: image006.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190301/5f1913da/attachment-0002.jpg>


More information about the Interest mailing list