Results 1 to 5 of 5

Thread: Qt Scripting Potentialities (ProcessingJS+QT)

  1. #1
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Qt Scripting Potentialities (ProcessingJS+QT)

    Hi guys, I am very interested in the potentialities of QT Scripting. I used rapid prototyping platforms like Processing in the past. Its recent online version ProcessingJS seems to be pretty popular and proved Processing to be a good language for visualizations. I am very interested to see if QT could be used to build more performant visualisations than the Java Processing itself. I presume it shouldn't be hard to build a javascript middle layer to communicate to OpenGL, I am just a bit concerned about the javascript execution speed (since big part of the logic, the user code, could still be there).

    What do you reckon? Does it worth investigating? Is there anyone who wants to be involved?

    Thanks for any info/opinion, cheers, chr

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

    Default Re: Qt Scripting Potentialities (ProcessingJS+QT)

    I made a test with random() and when Javascript and Processing Java take around 5ms to generate 100,000 numbers, QT engine takes > 20 ms. I am not particularly surprised, but this seems to be a show stopper for my purposes

    Clearly QT Script hasn't been created to compute demanding operations, and this is totally understandable.


    Thanks, chr

  3. #3
    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: Qt Scripting Potentialities (ProcessingJS+QT)

    Well, did you try creating a script function that calls a C++ function to generate those numbers?

    You can create wrapper functions for your scripts. Keep performance demanding functions in C++ and provide wrapper or access functions in your scripts.

  4. #4
    Join Date
    May 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Qt Scripting Potentialities (ProcessingJS+QT)

    Qt Code:
    1. // .cpp
    2. QScriptValue random(QScriptContext *context, QScriptEngine *engine)
    3. {
    4. float r = (float) rand()/RAND_MAX;
    5. int len = context->argumentCount();
    6. if(len == 0){
    7. return r;
    8. }
    9. QScriptValue a = context->argument(0);
    10. if(len == 1){
    11. return r * a.toNumber();
    12. }
    13. Q_ASSERT(len < 3);
    14. QScriptValue b = context->argument(1);
    15. return a.toNumber() + (b.toNumber() - a.toNumber()) * r;
    16. }
    To copy to clipboard, switch view to plain text mode 

    linked

    Qt Code:
    1. engine.globalObject().setProperty("random", engine.newFunction(random));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // .js
    2. var m = new Date().getTime();
    3. var num;
    4. for(var i=0; i<100000; i++){
    5. num = random(10,200);
    6. }
    7. println("qt processed in " + (new Date().getTime() - m));
    To copy to clipboard, switch view to plain text mode 


    Cheers, chr

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

    Default Re: Qt Scripting Potentialities (ProcessingJS+QT)

    Quote Originally Posted by tbscope View Post
    You can create wrapper functions for your scripts. Keep performance demanding functions in C++ and provide wrapper or access functions in your scripts.
    Sure, but the purpose of the experiment was to let the user write the whole application in js and just provide some global functions for the OpenGL rendering.

    Cheers, chr

Similar Threads

  1. Scripting question
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2008, 14:54
  2. Scripting engine
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2006, 11:36
  3. Scripting questions
    By fullmetalcoder in forum General Discussion
    Replies: 1
    Last Post: 22nd May 2006, 13:02

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.