QScriptEngine engine; QScriptValue global = engine.globalObject(); global.setProperty("greeting", QScriptValue(engine, "Hello World!"));
QScriptEngine engine; QScriptValue global = engine.globalObject(); global.setProperty("add", QScriptValue(engine, [](QScriptContext *context, QScriptEngine *engine) { int sum = 0; for (int i = 0; i < context->argumentCount(); ++i) { sum += context->argument(i).toNumber(); } return QScriptValue(engine, sum); }));This example sets a global function "add" that takes any number of arguments and returns their sum. The QScriptEngine class is part of the QtScript package library.