Results 1 to 5 of 5

Thread: How to compile script in QScriptEngine without calling evaluate function

  1. #1

    Default How to compile script in QScriptEngine without calling evaluate function

    Hi ,
    I am using QscriptEngine to provide scripting in my application. QScriptEngine will compile javascript script while evaluation. it works. but i need to compile the script, save it and evaluate after sometime. Compilation is mandatory before evaluation because when i evaluate script my application is in running state and any error from script is not acceptable. How can i achieve this?

  2. #2
    Join Date
    Aug 2012
    Location
    Montreal
    Posts
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to compile script in QScriptEngine without calling evaluate function

    Use the QScriptProgram.

    http://doc.qt.io/qt-4.8/QScriptProgram

    QScriptProgram retains the compiled representation of the script if possible. Thus, QScriptProgram can be used to evaluate the same script multiple times more efficiently.
    You can also use the QScriptEngine::checkSyntax() to make sure your code is well formatted. But you won't know if an error will happen in your code until you run simply because that's how JavaScript works. E.G.: if you write in JS "console.print(messageString);", it will compile even if there is no such thing as the "console". This is because the access to console actually compiles to a dictionary access on the global namespace just like "global["console"].methods["print"](messageString)".

    - Maxime

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to compile script in QScriptEngine without calling evaluate function

    Quote Originally Posted by sheetalw View Post
    Compilation is mandatory before evaluation because when i evaluate script my application is in running state and any error from script is not acceptable. How can i achieve this?
    You can't. QScriptProgram won't help. And before you ask your next question -- no, Qt is not to blame, it's not possible to do what you require because of the nature of Javascript.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4

    Default Re: How to compile script in QScriptEngine without calling evaluate function

    thanks. actually not just javascript, scripts are meant to compile and run at the same time. and i am not going to blame Qt, I just tried, may be i could get some other tool, i am a beginner don't know much abt qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to compile script in QScriptEngine without calling evaluate function

    I'm not talking about other languages, I'm talking about JavaScript. The same code can be valid now but be invalid next time you call it (or vice versa). There are no guarantees that can be made upfront. You can only do a syntax check which captures only the most trivial problems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 26th April 2012, 12:50
  2. Interrupting script evaluation of QScriptEngine
    By Haqim in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2010, 14:38
  3. Calling QPrintDialog from script
    By rikardo in forum Qt Programming
    Replies: 0
    Last Post: 1st June 2009, 09:19
  4. Interpretting .pac script using QScriptEngine()
    By Saranakumardb in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2008, 12:12
  5. term does not evaluate to a function
    By :db:sStrong in forum General Programming
    Replies: 6
    Last Post: 18th April 2007, 10:54

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.