Generate JS object with embedded context property generated from text?
Unsolved
QML and Qt Quick
-
I have a set of context properties defined by another object. They are contiguous in their naming as xmBtn1 ... xmBtn6. I want to handle these in QML in a similar manner. How do I go about generating an object with a reference to these context properties without explicitly making a list of them: property var objs: [xmBtn1, xmBtn2, ... xmBtn6]?
I tried to generate a JSON object by parsing, but the object lacks context and fails to generate:
let buttons = [] for(let ind=0; ind<6; ++ind){ let str = "{button: %1}".arg("xmBtn%1".arg(ind+1)) console.log(str) buttons.append(JSON.parse(str)) }
Output:
qml: {button: xmBtn1} SyntaxError: JSON.parse: Parse error
Pretty sure JSON.parse doesn't know what to do with xmBtn1 as that is not in the context of the parse.
Is there a function in QML I can call that can retrieve a valid object to a symbol that is defined in the context?
Something like: Qt.getproperty("propertyname") ?