Hi all,

Could someone explain QObject ownershiping aspects, please.

According to
http://doc-snapshots.qt.io/qt5-dev/qtqml-cppintegration-data.html when data
is transferred from C++ to QML, the ownership of the data always remains
with C++. The exception to this rule is when a QObject is returned from an
explicit C++ method call.

And it works for c++ functions that return "single" QObject*.

But what to do with QObjectList-based models (
https://doc-snapshots.qt.io/qt5-5.9/qtquick-modelviewsdata-cppmodels.html)?
Let say in c++ application creates list of new objects:
Q_INVOKABLE QList<QObject *> workers();
and qml set this as the model for ListView or Combobox.

But these objects will never be destroyed. How to force qml own this
objects properly?

I did try QQmlEngine::setObjectOwnership(list[i],
QQmlEngine::JavaScriptOwnership) in loop before returning list, but qml can
destroy them immediately despite that Combobox is still displayed.

--
With regards, Oleg.
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to