4

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?

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. Commented Aug 10, 2017 at 7:44

1 Answer 1

7

You 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, moved code to a js include and all object creation worked fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.