据我记得QtScriptDebugger
应该结合QtScriptEngine
以下方式使用:
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");
}
因此,当您将debugger;
命令添加到脚本文本时,应该会出现调试器窗口