QJSEngine removes my QObject, how do I change ownership after QJSEngine :: newQObject?

Trying to execute a small script with a subclass of QObject as a parameter.

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

QJSValue result = function.call(QJSValueList() << arg);

When killing jsEngine, it calls delete for my child object (since newQObject creates it using JavaScriptOwnership). How to avoid this, how to change ownership of arg?

Script is simple:

function(device) { 
    return device.m_place >=0 && device.m_place < 16; 
}

UPD: It can be called QQmlEngine::setObjectOwnership(child, QQmlEngine::CppOwnership);for an object, since it is a static function. This is just not clear from the help. Think it should be in QJSEngine.

+4
source share
1 answer

QQmlEngine:: setObjectOwnership (child, QQmlEngine:: CppOwnership); , . . , QJSEngine.

+1

All Articles