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.