[Interest] Accessing the raw value of QQmlScriptString (QDeclarativeScriptString::script)

Jan Kundrát jkt at flaska.net
Thu Sep 5 11:08:27 CEST 2013


On Wednesday, 4 September 2013 23:18:21 CEST, Michael Brasser wrote:
> The QQmlExpression constructor that takes a QQmlScriptString 
> allows setting a custom context and scope object to replace the 
> default one provided by the QQmlScriptString. Is this enough to 
> accomplish what you need?

Could be, I guess. I don't have enough insight into how much overhead this 
would impose, though (there is no point in keeping the original context 
around if it's going to be discarded anyway, etc.). I still like passing 
just the actual string expression around, and delegating optimizaiton like 
precompiling it, setting up a proper context etc etc until the point it is 
used for validating the user-provided data.

Another reason for this is to be able to treat both modules separately -- 
the fact that the validation also happens to use the QML engine behind the 
scene shall, IMHO, remain as an implementation detail.

> This was removed in commit 
> aa25ad8d5f476d6db59012a122833ebe677eaf69 ("Allow for future 
> optimization by encapsulating the raw script data."). 
> Unfortunately I do not remember the details of the optimizations 
> being discussed at the time (it may have been related to memory 
> consumption, or to pre-compiling QML, or to early prototypes of 
> v4).

Looks like I *can* get away with working with strings by extracting the 
actual script value roughly like this:

  QString text = QQmlExpression(scriptString).expression();

The only difference is that the expression text is now wrapped by 
"(function $() { return XYZ })" where XYZ is the original expression. I 
could either strip this extra wrapping, or just append "()" to the end of 
the expression.

So, shall I just stop worying about this and start passing QQmlScriptString 
instances around (and if so, why)? Or shall I keep my "()" hack for now? To 
me, the best course of action seems to be adding the script() accessor 
back, but one would have to check that the returned data do not include the 
wrapping, IMHO.

With kind regards,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/



More information about the Interest mailing list