Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
5.15.16, 6.2.11
Description
Reproducer attached. Run it with Qt 5.15 or 6.2 and it crashes at about (in my case) 1600th update to "MyObject*" which is a QObject* defined on C++ side and returned to QML side as the "text" property of Text.
Uncomment 4 "QQmlEngine::setObjectOwnership(data, QQmlEngine::CppOwnership);" lines in myObjectModel.cpp, and problem is gone.
So what is happening is that (I think) MyObject* is returned to QML side directly from a C++ function call, then its ownership is transferred to QML engine. And QML engine garbage-collects it by mistake (so giving ownership back to C++ avoid it from happening). But at this point, MyObject* itself is not destroyed. Actually I am not 100% what is going on by:
Memory Management in the JavaScript Engine | Qt QML 6.6.1
What I suppose is that the "wrapper" is gc()'ed, so does the pointer to C++ heap where MyObject* locates. But MyObject* is still alive.
But anyway, run the sample with Qt6.6 then no error happens even without setting ownership. So something must be backported. but I don't know what yet.