PDA

View Full Version : QtScript - How to use maths functions in a script?



behu
18th October 2010, 08:28
Hello,
I started to use script in qt a few days ago,
but I have a very basic (I suppose) problem :
how to use the maths function in a script?
(Because if I understand correctly theses functions exist : http://doc.trolltech.com/main-snapshot/ecmascript.html).
Maybe it is related to "importExtension("qt.core")" but I do not succeed to make it working.
Thanks a lot.

Here is an example of code I want to use :


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QScriptEngine testEngine;
QString content = "var stuff = cos(50);";

QScriptSyntaxCheckResult result = QScriptEngine::checkSyntax (content );
if(result.state() != QScriptSyntaxCheckResult::Valid){
QMessageBox::warning(0,"Erreur de syntaxe",result.errorMessage());
return -1;
}

testEngine.evaluate(content);

if (testEngine.hasUncaughtException()) {
QMessageBox::warning(0,"Erreur d'execution", testEngine.uncaughtException().toString());
}

return a.exec();
}


This code returns "cos is undefined" from the evaluation.

tbscope
18th October 2010, 08:47
Use


Math.cos

Or something like that.

behu
18th October 2010, 08:57
Yes, you'are right!
Thanks a lot!!
(I feel like an idiot :o )