Results 1 to 3 of 3

Thread: QtScript - How to use maths functions in a script?

  1. #1
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QtScript - How to use maths functions in a script?

    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 :
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. QScriptEngine testEngine;
    6. QString content = "var stuff = cos(50);";
    7.  
    8. QScriptSyntaxCheckResult result = QScriptEngine::checkSyntax (content );
    9. if(result.state() != QScriptSyntaxCheckResult::Valid){
    10. QMessageBox::warning(0,"Erreur de syntaxe",result.errorMessage());
    11. return -1;
    12. }
    13.  
    14. testEngine.evaluate(content);
    15.  
    16. if (testEngine.hasUncaughtException()) {
    17. QMessageBox::warning(0,"Erreur d'execution", testEngine.uncaughtException().toString());
    18. }
    19.  
    20. return a.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QtScript - How to use maths functions in a script?

    Use

    Qt Code:
    1. Math.cos
    To copy to clipboard, switch view to plain text mode 

    Or something like that.

  3. The following user says thank you to tbscope for this useful post:

    behu (18th October 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QtScript - How to use maths functions in a script?

    Yes, you'are right!
    Thanks a lot!!
    (I feel like an idiot )

Similar Threads

  1. Replies: 3
    Last Post: 22nd October 2010, 19:49
  2. Replies: 4
    Last Post: 11th May 2010, 17:33
  3. Replies: 1
    Last Post: 27th February 2010, 10:33
  4. QtScript. How to add created object to script?
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2010, 14:24
  5. QtScript: how to reload current script?
    By eyeofhell in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2010, 10:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.