QScriptEngine engine; QScriptValue value = engine.evaluate("'Hello World'"); QString str = value.toString(); // str = "Hello World"
QScriptEngine engine; QScriptValue value = engine.evaluate("function add(a, b) { return a + b; }"); QString str = value.toString(); // str = "function add(a, b) { return a + b; }"In this example, a QScriptEngine is created and a script is evaluated to create a QScriptValue object representing a function. The value.toString() function is called to convert the QScriptValue object to a QString that equals the entire script. Package library: Qt Core.