Replying to share my personal experience with this issue.
Changing the ownership of the instantiated object to "QQmlEngine::CppOwnership":http://doc.qt.io/qt-5/qqmlengine.html#ObjectOwnership-enum before returning it indeed fixes the issue.
What is not very intuitive though is the fact that you have to change the ownership to CppOwnership even if the objectOwnership() method already returns CppOwnership. This gives something like:
@QObject *
MyClass::InvokableMethod ( ... )
{
QObject * pObject = InstanciateObject( ... );
QQmlEngine::ObjectOwnership ow = engine->objectOwnership( pObject );
// Here, ow == QQmlEngine::CppOwnership
engine->setObjectOwnership( pObject, QQmlEngine::CppOwnership );
return pObject;
}@
The "setObjectOwnership()":http://doc.qt.io/qt-5/qqmlengine.html#setObjectOwnership and "objectOwnership()":http://doc.qt.io/qt-5/qqmlengine.html#objectOwnership methods seem to perform more stuff than just set and get a two-value property on the object, something that does not appear in the documentation.
Anyway, thanks for the post.