[Development] Problem with QML garbage collection (Qt 5.15)

Alberto Mardegan mardy at users.sourceforge.net
Sat Apr 30 23:40:32 CEST 2022

Hi there!

   I think I'm experiencing an issue related to

In my case, I have a C++ method returning a new QObject, which has 
automatic Javascript ownership. This is fine, because indeed I want to 
have my object managed by the QML engine.

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 

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

More information about the Development mailing list