QML: List all object members/properties in console

tirth picture tirth · Nov 29, 2013 · Viewed 22.1k times · Source

Is there any way to list all object members/properties in QML & Qt 5.1?

Such as:

var obj=myQObject;
console.log(obj)
// expected output:
// obj { x:123..... }

This would be very helpful for debugging.

Answer

kevinf picture kevinf · Apr 4, 2014

Straight javascript offers what you are looking for:

JSON.stringify(anything)

It works on QML items such as Rectangle, and it also works on most arbitrary objects!

Converting an object to a string