Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

How to get eval() to operate in the scope of QML element

$
0
0
If I have some JS code as text and I call it in eval(), I can then use the functions defined by this statement only in the scope of where the eval() occurred. As far as I can tell, this means that any new JS definitions created from the eval are invisible to the rest of QML. Consider this QML signal handler:                Item {        id: testitem        onThesourceChanged: {             eval(thesource)             testfunction()         }        } The testfunciton() was defined in the text “thesource” and does indeed work; but it is not in the scope of the QML element and therefore cannot be called ever again, as far as I can see. I’ve tried various ideas like putting the eval() in a function, or inside Component.onCompleted, etc, but I can’t seem to figure out how to get anything created by the eval() to be recognized as part of the parent QML element. For example I want to be able to call testitem.testfunction() — but it is not defined outside the scope of this handler. Can anyone assist?

Viewing all articles
Browse latest Browse all 4972

Trending Articles