Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
I had a Q_INVOKABLE method returning a QObject-derived class from C++ to QML. By default, such methods apply QQmlEngine::JavaScriptOwnership to the object. (https://doc.qt.io/qt-6/qtqml-cppintegration-data.html#data-ownership)
I later decided to refactor the method to return a QIfPendingReply instead to make the method async. I created the object on a separate thread and used setSuccess to assign it to the reply. What I didn't realize was that I would have to manually set JavaScript Ownership on the object to avoid memory leaks.
While this may seem obvious, I believe it might cause some headaches that could be avoided with a warning in the docs.