Results 1 to 5 of 5

Thread: qtscript

  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question qtscript

    Hello everyone,

    Now I want do a formula editor with qt,which provide an interface to user to edit there own formula by

    qtscript. So it needs some base functions just like add,subtract and so on.

    I want write these functions in a javascript file, and then invoke this file in my qtscript text. But I try some

    ways to invoke that file,it is not effective.

    Anyone can give me some suggestions?

  2. #2
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qtscript

    no one reply me.
    I tell a way I just hava try.

    Qt Code:
    1. function include_js(path,reload)
    2. {
    3. var scripts = document.getElementsByTagName("script");
    4. if (!reload)
    5. for (var i=0;i < scripts.length;i++)
    6. if (scripts[i].src && scripts[i].src.toLowerCase() == path.toLowerCase() ) return;
    7. var sobj = document.createElement('script');
    8. sobj.type = "text/javascript";
    9. sobj.src = path;
    10. var headobj = document.getElementsByTagName('head')[0];
    11. headobj.appendChild(sobj);
    12. }
    13.  
    14. include_js("test.js",0);
    To copy to clipboard, switch view to plain text mode 

    but this is the warning: Can't find variable: document. ..

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qtscript

    Correct. QtScript doesn't have document variable. Its not running from within a html page, so there is none.

    Please check the QtScript examples directory.

  4. #4
    Join Date
    Jun 2010
    Posts
    38
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qtscript

    Quote Originally Posted by fatjuicymole View Post
    Correct. QtScript doesn't have document variable. Its not running from within a html page, so there is none.

    Please check the QtScript examples directory.
    yes,I know,but in my script,I need use "test.js" this file.

    so is there any ways to do?

  5. #5
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qtscript

    Mhm why not use the build in functionality.

    I did something like this:

    Qt Code:
    1. QScriptEngine engine;
    2. for (int x=0; x<size_x ; x++)
    3. {
    4. engine.globalObject().setProperty("x",x);
    5. double value=engine.evaluate(QString("with (Math) {")
    6. +mUi.mpLineEditParserFunctionString>text()
    7. +QString("}")).toNumber();
    8. my_function->SetValuel(x,value);
    9. }
    To copy to clipboard, switch view to plain text mode 

    then people can type their formulas into the lineedit like x*sin(x)*exp(-x*x)

Similar Threads

  1. QtScript
    By lamosca in forum Newbie
    Replies: 2
    Last Post: 20th May 2010, 23:01
  2. Replies: 0
    Last Post: 25th November 2009, 07:46
  3. QtScript Questions
    By Scorp2us in forum Qt Programming
    Replies: 9
    Last Post: 29th June 2009, 22:06
  4. Please help with QtScript
    By Haccel in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2008, 05:59
  5. QtScript
    By QTInfinity in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2008, 20:10

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
  •  
Qt is a trademark of The Qt Company.