PDA

View Full Version : My own print function in Qt Script



zack
18th February 2009, 11:42
I dont know why, but nothing is printed to my QtScript Debugger console, does anybody know why?


QScriptValue Debug_Function(QScriptContext *ctx, QScriptEngine *)
{
QString result;
for (int i = 0; i < ctx->argumentCount(); ++i)
{
if (i != 0)
result.append(QLatin1String(" "));

QString s = ctx->argument(i).toString();
if (ctx->state() == QScriptContext::ExceptionState)
break;
result.append(s);
}
return ctx->engine()->toScriptValue(result);
}




QScriptValue dfunc = engine.newFunction(Debug_Function);

engine.globalObject().setProperty("debug", dfunc);

seneca
18th February 2009, 11:48
How about this:


QScriptValue Debug_Function(QScriptContext *ctx, QScriptEngine *)
{
QString result;
for (int i = 0; i < ctx->argumentCount(); ++i)
{
if (i != 0)
result.append(QLatin1String(" "));

QString s = ctx->argument(i).toString();
if (ctx->state() == QScriptContext::ExceptionState)
break;
result.append(s);
}
qDebug() << result;
return ctx->engine()->toScriptValue(result);
}

zack
18th February 2009, 12:24
that doesn't work. I did not see the result string in the Qt Script Debugger "Debug Output" widget.

seneca
18th February 2009, 13:50
Well the term "debug output" is missleading, actually it does not display debug output but:


The debug output widget shows messages generated by the print() script function. Scripts can use the special variables __FILE__ and __LINE__ to include the current location information in the messages.

So either just use print, or hack the debugger to also redirect debug output to that window.