3

I'm trying to create a benchmark for part of my 2D game framework (It's a QML extension) and I'm having problems to set a declarative script property of a QOBject.

The property declaration:

Q_PROPERTY(QDeclarativeScriptString script READ script WRITE setScript NOTIFY scriptChanged)

And one of my attempts to change the script is something like this:

ScriptBehavior *behavior = new ScriptBehavior(entity);
QDeclarativeProperty(behavior, "script").write("console.log(1);");

But it doesn't work (Run the benchmark, but don't write anything to te console).

I've tried to use setProperty and manually create a QDeclarativeScriptString and set the property, but nothing works.

When I try to create the QDeclarativeScriptString, It fails:

The code:

ScriptBehavior *behavior = new ScriptBehavior(entity);
QDeclarativeScriptString scriptString;
scriptString.setScript("console.log(1)");
behavior->setScript(scriptString);

The output:

QFATAL : UpdateBenchmark::behavior() Received signal 11
FAIL!  : UpdateBenchmark::behavior() Received a fatal error.
   Loc: [Unknown file(0)]

Any help?

Thanks

rzan
  • 426
  • 1
  • 3
  • 10
  • 1
    How are you evaluating the QDeclarativeScriptString? Presumably via QDeclarativeExpression, in which case you'll need a context and scriptObject also. – MartinJ Aug 08 '12 at 04:51
  • Yup, I create a QDeclarativeExpression when setting the script: m_expression = new QDeclarativeExpression(m_script.context(), m_script.scopeObject(), m_script.script()); and then just call evaluate() when needed. – rzan Aug 08 '12 at 13:30

0 Answers0