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[])
{
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
This code returns "cos is undefined" from the evaluation.
Bookmarks