[Development] Problem with QML garbage collection (Qt 5.15)
furkanuzumcu at gmail.com
Sun May 1 19:01:24 CEST 2022
I think adding an object to a `ListModel` does not alter its ownership. If the page with the initial property which holds a reference to the object returned from the C++ method is destroyed, then I would expect that object to be destroyed as well. Personally, I usually prefer to control the life time of an object by the C++ side or by instantiated types in the QML side. Unless I’m wrong about `ListModel` not taking ownership in `append`, I’d recommend not tempering with the object ownership rules manually. Also, is there a code sample that you can provide for this?
> On Apr 30, 2022, at 17:40, Alberto Mardegan <mardy at users.sourceforge.net> wrote:
> Hi there!
> I think I'm experiencing an issue related to
> Then I'm passing the object as a property to a subpage, and also storing it into a ListModel (by calling append()). If I navigate to the subpage where I passed my object as a property, I can see that it is working fine. If I then navigate to another page where I have a ListView operating on that ListModel where I added my object, that works fine as well.
> The problem happens when I navigate back from the page with the ListView. It seems to me, that when that page gets destroyed my object gets destroyed as well, despite being still used in the ListModel (which is never getting destroyed).
> I'm working around this by setting the ownership to C++ and never actually destroying the objects (since I have few of them anyways), but I suspect that this might be a bug in the garbage collection.
> http://www.mardy.it - Geek in un lingua international
> Development mailing list
> Development at qt-project.org
More information about the Development