加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – QJSEngine删除我的QObject,如何在QJSEngine :: newQObject

发布时间:2020-12-16 07:09:56 所属栏目:百科 来源:网络整理
导读:尝试使用子类QObject作为参数执行小脚本. QJSEngine jsEngine;QJSValue arg = jsEngine.newQObject(child); // Child it's subclassed QObjectQJSValue function = jsEngine.evaluate(m_childRestriction);QJSValue result = function.call(QJSValueList() a
尝试使用子类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);

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

脚本很简单:

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

UPD:
可以调用QQmlEngine :: setObjectOwnership(child,QQmlEngine :: CppOwnership);因为它是静态函数.它只是不明白的帮助.认为它也应该在QJSEngine中.

解决方法

可以调用QQmlEngine :: setObjectOwnership(child,QQmlEngine :: CppOwnership);因为它是静态函数.它只是不明白的帮助.认为它也应该在QJSEngine中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读