String to Function ?
-
Is there a way to convert a string to a function in pure QML?
for instance
function hello() { console.log("hello") } var s = "{console.log('hi')}" hello = stringToFunction(s) hello()//outputs "hi"It looks like Qt.createComponent() and Qt.createQmlObject() will create an entire class.
I want to re-assign a value to a pre-existing function. -
There is no such function.
Perhaps this will help you, though: https://stackoverflow.com/questions/13521833/javascript-add-method-to-object
-
Is there a way to convert a string to a function in pure QML?
for instance
function hello() { console.log("hello") } var s = "{console.log('hi')}" hello = stringToFunction(s) hello()//outputs "hi"It looks like Qt.createComponent() and Qt.createQmlObject() will create an entire class.
I want to re-assign a value to a pre-existing function.@JeTSpice
Alternatively, you may use JavaScripteval(), provided the JS does not "block" it and you understand that it is considered a "security risk" (though not here, as you know what the text is). For a function definition:eval("function hello() { console.log('hi'); }");