admin管理员组文章数量:1419235
I'm trying to create a new javascript object in QML.
In javascript I would simply:
var newObject = new Object();
but this is flagged as an error by QtCreator
Can anyone help?
I'm trying to create a new javascript object in QML.
In javascript I would simply:
var newObject = new Object();
but this is flagged as an error by QtCreator
Can anyone help?
Share Improve this question edited Aug 9, 2017 at 21:24 derM 13.7k5 gold badges60 silver badges98 bronze badges asked Aug 9, 2017 at 17:26 readysteadygo2006readysteadygo2006 531 silver badge3 bronze badges 1- Could you add some more code? Could you cite the exact error message? I get a feeling that you mixed QML and JS code. Please have in mind that QML contains QML code which is not JS. You can embed JS in QML easily but not just by putting JS anywhere in QML file. Have a look at examples. – Filip Hazubski Commented Aug 10, 2017 at 7:44
1 Answer
Reset to default 7You don't need new
. You can just create an empty JS Object like this in a script part (e.g. signal handler, function etc.)
var newObject = {} // In a script.
or as a property:
property var someObject: ({}) // You need to wrap it in paranthesis
If you insist on the new
-keyword
var someOtherObject = new Object // In a script
seems to be working, too.
本文标签: Creating a new javascript object in QMLStack Overflow
版权声明:本文标题:Creating a new javascript object in QML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745290054a2651738.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论