Пример #1
0
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
QJSEngine myEngine;
QJSValue three = myEngine.evaluate("1 + 2");
//! [0]


//! [1]
QJSValue fun = myEngine.evaluate("(function(a, b) { return a + b; })");
QJSValueList args;
args << 1 << 2;
QJSValue threeAgain = fun.call(QJSValue(), args);
//! [1]


//! [2]
QString fileName = "helloworld.qs";
QFile scriptFile(fileName);
if (!scriptFile.open(QIODevice::ReadOnly))
    // handle error
QTextStream stream(&scriptFile);
QString contents = stream.readAll();
scriptFile.close();
myEngine.evaluate(contents, fileName);
//! [2]

Пример #2
0
qmlbind_value qmlbind_value_call(qmlbind_value self, int argc, qmlbind_value *argv)
{
    QJSValue func = *self;
    return new QJSValue(func.call(pack_args(argc, argv)));
}
static void deepFreeze(QJSEngine *jsEngine, const QJSValue &obj)
{
    QJSValue freezeFunc = jsEngine->evaluate(QString::fromUtf8(FREEZE_SOURCE));
    freezeFunc.call(QJSValueList() << obj);
}