I love the new QtScript module added to Qt 4.3, and I got the engine to do exactly what I wanted very quickly. But now I'm trying to add functions to the engine, specifically one that prints the arguments in a QTextEdit. I have looked at the documentation for QScriptEngine::newFunction, bit I just can't get it to work. Here is my code:
QScriptValue printString(QScriptContext *context, QScriptEngine *engine){
for(int i=0; i<context->argumentCount(); i++){
//outputText->append(context->argument(i).toString());
}
return context->callee();
}
void MainWindow::setupScripts(){
engine = new QScriptEngine();
QScriptValue fun = engine->newFunction(printString);
engine->globalObject().setProperty("print", fun, QScriptValue::ReadOnly | QScriptValue::Undeletable);
}
QScriptValue printString(QScriptContext *context, QScriptEngine *engine){
for(int i=0; i<context->argumentCount(); i++){
//outputText->append(context->argument(i).toString());
}
return context->callee();
}
void MainWindow::setupScripts(){
engine = new QScriptEngine();
QScriptValue fun = engine->newFunction(printString);
engine->globalObject().setProperty("print", fun, QScriptValue::ReadOnly | QScriptValue::Undeletable);
}
To copy to clipboard, switch view to plain text mode
Whenever the code is compiled, I get the following error:
...:error: no matching function for call to `QScriptEngine::newFunction(<unknow type>)`
...:error: no matching function for call to `QScriptEngine::newFunction(<unknow type>)`
To copy to clipboard, switch view to plain text mode
Anyone know why this might be?
Bookmarks