0

I've been traying to make some implementation using QtScript and QScriptDebugger, but I wonder if ayone have information regarding the following topic.

When using the function attachTo() of QtScriptDebugger, in the documentation it says that it set a "custom" QScriptAgent and that if I would like to have more monitoring regarding my script execution I should create a Proxy Agent and fordward the required events to this "custom" script engine setted by the ScriptDebugger to the ScriptEngine.

So how can I make or implement this kind of proxy agent to forward the events? I think I get the main idea/concept behind this stuff, but I just can't find anything on the web and I haven't figured it out yet so that's why I ask for some help.

Hopefully someone has some information regarding this topic!

Thanks in advance!

Qnoobish
  • 148
  • 11

1 Answers1

0

As far as I remember QtScriptDebugger should be used in conjunction with QtScriptEngine the following way:

QtScriptEngine *engine = new QtScriptEngine();
engine->setProcessEventsInterval(50); // this is required to prevent your interface from hanging up during using of debugger
QScriptEngineDebugger *scriptDebugger = new QScriptEngineDebugger(engine);
scriptDebugger->setAutoShowStandardWindow(true); // this makes the debugger window to appear when 'debugger;' instruction occurs
scriptDebugger->attachTo(engine); // this incorporates your script engine with its debugger
// ...
// your custom manipulations follows
// ...

// suppose you have some script attributes set
QMap<QString, QScriptValue> scriptAttributes;

// setup global attributes used in your scripts
QScriptValue global = engine->globalObject();
foreach (const QString &varName, scriptAttributes.keys()) {
    global.setProperty(varName, scriptAttributes.value(varName));
}

// check script syntax
QScriptSyntaxCheckResult syntaxResult = engine->checkSyntax(scriptText);
if (QScriptSyntaxCheckResult::Valid != syntaxResult.state()) {
   // report syntax error
}

// run the script
QScriptValue result = engine->evaluate(scriptText);

if (engine->hasUncaughtException()) {
    /// report script run-time error
    qDebug() << QString("Exception during script execution! Line: %1, error: %2")
                    .arg(engine->uncaughtExceptionLineNumber()).arg(engine->uncaughtExceptionBacktrace().join("\n");
}

So when you add to your script text the debugger; command, debugger window should appear

Ivan
  • 588
  • 5
  • 20