On Saturday, 8 December 2012 11:34:17 CEST, Andy Mayer wrote:
> I have a question regarding the possibilty of reading the body 
> of a javascript function from c++. I want to create a DSL based 
> on QML and I have to read the body of a javascript function.
>
> e.g.
>
> QML:
>   Item {
>       function action() {
>           console.log("Got message:", msg)
>           return "some return value"
>       }
>   }

You can achieve a similar result through the QDeclarativeScriptString and 
QDeclarativeExpression. The key is to define a (C++) property of type 
QDeclarativeScriptString. The engine will make sure that it's a reasonably 
formed JS and will make the actual text as a string available to you. You can 
then take the actual script string, the QML context and the scope object and 
construct and evaluate the QDeclarativeExpression yourself.

The disadvantage is that the value shall really be an expression, not a 
function. You can still call functions from that expression, but I suspect that 
their resolving will only work if you preserve the original scope. You also 
won't gain access to the source of these functions, just to your expression.

With kind regards,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to