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:
function drawCircle()
{
center(10, 10);
radius(10);
}
function drawCircle()
{
center(10, 10);
radius(10);
}
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:
QJSValue function = jsEngine->evaluate("function drawCircle() {center(x, y); radius(r);}");
QJSValueList args;
args << 1;
QJSValue result = function.call(args);
int rslt = result.toInt();
qDebug() << rslt;
QJSValue function = jsEngine->evaluate("function drawCircle() {center(x, y); radius(r);}");
QJSValueList args;
args << 1;
QJSValue result = function.call(args);
int rslt = result.toInt();
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.
Bookmarks