QJSEngine删除我的QObject,如何在QJSEngine :: newQObject之后更改所有权?

Ser*_*hiy 5 c++ qt qjsengine

尝试使用子类化的QObject作为参数执行小型脚本。

QJSEngine jsEngine;
QJSValue arg = jsEngine.newQObject(child); // Child it's subclassed QObject
QJSValue function = jsEngine.evaluate(m_childRestriction);

QJSValue result = function.call(QJSValueList() << arg);
Run Code Online (Sandbox Code Playgroud)

在销毁jsEngine时,它将为我的子对象调用delete(因为newQObject使用JavaScriptOwnership创建了它)。如何避免这种情况,如何更改arg的所有权?

脚本很简单:

function(device) { 
    return device.m_place >=0 && device.m_place < 16; 
}
Run Code Online (Sandbox Code Playgroud)

UPD: 可以调用QQmlEngine::setObjectOwnership(child, QQmlEngine::CppOwnership);对象,因为它是静态函数。从帮助中还不清楚。认为也应该在QJSEngine

Ser*_*hiy 4

可以调用 QQmlEngine::setObjectOwnership(child, QQmlEngine::CppOwnership); 对于对象,因为它是静态函数。只是从帮助中还不清楚。我认为它也应该在 QJSEngine 中。