QJSEngine deletes my QObject, how to change ownership after QJSEngine::newQObject?

不打扰是莪最后的温柔 提交于 2019-12-10 15:09:18

问题


Trying to perform small script with subclassed QObject as parameter.

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

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

On destroying jsEngine, it calls delete for my child object (as newQObject creates it with JavaScriptOwnership). How to avoid it, how to change ownership for arg?

Script is simple:

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

UPD: It is possible to call QQmlEngine::setObjectOwnership(child, QQmlEngine::CppOwnership); for the object as it is the static function. It just not clear from the help. Think it is suppose to be in QJSEngine also.


回答1:


It is possible to call QQmlEngine::setObjectOwnership(child, QQmlEngine::CppOwnership); for the object as it is the static function. It just not clear from the help. Think it is suppose to be in QJSEngine also.



来源:https://stackoverflow.com/questions/26177693/qjsengine-deletes-my-qobject-how-to-change-ownership-after-qjsenginenewqobjec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!