Results 1 to 4 of 4

Thread: Scripting in Qt

  1. #1
    Join Date
    Aug 2014
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Scripting in Qt

    I have a widgets application. I am trying to implement scripting in this application.

    The user will create a script using javascript which will be executed on pressing a QPushButton.

    The script is expected to be of the form:

    Qt Code:
    1. function drawCircle()
    2. {
    3. center(10, 10);
    4. radius(10);
    5. }
    To copy to clipboard, switch view to plain text mode 
    I am trying to use QJSEngine class. How the evaluation of script is to be done?

    I have tried the following code snippet in the application:

    Qt Code:
    1. QJSValue function = jsEngine->evaluate("function drawCircle() {center(x, y); radius(r);}");
    2. QJSValueList args;
    3. args << 1;
    4. QJSValue result = function.call(args);
    5. int rslt = result.toInt();
    6. qDebug() << rslt;
    To copy to clipboard, switch view to plain text mode 

    Is this the right way to add scripting to the application? Please enlighten me on this.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Scripting in Qt

    In general yes, but you might want to look at QScriptEngine instead.
    Theoretically QJSEngine was intended to be its replacement but its non-QML development has been suspended for now.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2014
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Scripting in Qt

    Quote Originally Posted by anda_skoa View Post
    In general yes, but you might want to look at QScriptEngine instead.
    Theoretically QJSEngine was intended to be its replacement but its non-QML development has been suspended for now.
    _
    Okay. So I should use QScriptEngine. Can you point me out to some examples having form as I need?

  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: Scripting in Qt

    There is a bunch of examples on QtScript bundled with Qt.
    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. Simple Scripting language
    By shawk in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2012, 10:08
  2. Why prefer scripting instead Qt/C++ on webdevelopment?
    By Alir3z4 in forum Qt Programming
    Replies: 17
    Last Post: 12th November 2011, 04:09
  3. Scripting question
    By EricF in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2008, 15:54
  4. Scripting engine
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 27th October 2006, 12:36
  5. Scripting questions
    By fullmetalcoder in forum General Discussion
    Replies: 1
    Last Post: 22nd May 2006, 14:02

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.