Results 1 to 8 of 8

Thread: QSriptEngine and more than one script

  1. #1
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSriptEngine and more than one script

    I'm creating program with loadable scripts. User should be able to load several scripts from files. But there is a problem. Can I use different instances of QScriptEngine per script or maybe is better way for this?

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

    Default Re: QSriptEngine and more than one script

    Yes, you can. However it's probably better to only have one engine.
    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.


  3. #3
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSriptEngine and more than one script

    Quote Originally Posted by wysota View Post
    Yes, you can. However it's probably better to only have one engine.
    but how can I obtain clean environment for each script file? By QScriptEngine::pushContext() ? And what happens if I attach QScriptEngineDebugger to that one engine?

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

    Default Re: QSriptEngine and more than one script

    Quote Originally Posted by lukass View Post
    but how can I obtain clean environment for each script file? By QScriptEngine::pushContext() ?
    Yes, that's one way of doing that.

    And what happens if I attach QScriptEngineDebugger to that one engine?
    I don't understand your question. What do you mean what happens?
    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.


  5. #5
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSriptEngine and more than one script

    Quote Originally Posted by wysota View Post
    Yes, that's one way of doing that.
    If I use pushContext() then how can I "unload" particular script?
    And are there other ways? If so, how?

    Quote Originally Posted by wysota View Post
    I don't understand your question. What do you mean what happens?
    Now I also do not understand. I have to check it out.
    Last edited by lukass; 1st March 2012 at 11:27.

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

    Default Re: QSriptEngine and more than one script

    Quote Originally Posted by lukass View Post
    If I use pushContext() then how can I "unload" particular script?
    I don't understand what you mean.

    And are there other ways? If so, how?
    For example you could set a new global object for the engine.

    Let's make something clear -- one script engine only allows one script to be ran at the same time. If you want to run more (long running) scripts concurrently, you need separate engines however doing that in a single thread doesn't make much sense. Doing that in different threads requires you to synchronize access to all data shared between those scripts and also between your main program flow (aka "GUI thread").
    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.


  7. #7
    Join Date
    Aug 2008
    Posts
    50
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSriptEngine and more than one script

    Quote Originally Posted by wysota View Post
    I don't understand what you mean.
    For example I loaded three scripts by:
    Qt Code:
    1. engine.evaluate(script1);
    2. engine.pushContext();
    3. engine.evaluate(script2);
    4. engine.pushContext();
    5. engine.evaluate(script3);
    To copy to clipboard, switch view to plain text mode 
    I can unload last script by engine.popContext() but how can I unload first script?

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

    Default Re: QSriptEngine and more than one script

    The code you pasted doesn't make sense. The following should be fine:

    Qt Code:
    1. engine.pushContext();
    2. engine.evaluate(script1);
    3. engine.popContext();
    4. engine.pushContext();
    5. engine.evaluate(script2);
    6. engine.popContext();
    7. engine.pushContext();
    8. engine.evaluate(script3);
    9. engine.popContext();
    To copy to clipboard, switch view to plain text mode 

    You don't "unload" scripts. When a script has finished executing you don't have to do anything more with it.
    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. script
    By wookoon in forum Newbie
    Replies: 1
    Last Post: 19th July 2010, 09:47
  2. Using QT Script...
    By minhaz in forum Newbie
    Replies: 1
    Last Post: 18th August 2009, 22:29
  3. Qt Script
    By c_srikanth1984 in forum Qt Programming
    Replies: 3
    Last Post: 9th June 2009, 10:35
  4. Can I include a script from script?
    By yycking in forum Qt Programming
    Replies: 1
    Last Post: 24th April 2009, 03:01
  5. Qt script
    By rajesh_clt3 in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 12:40

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.