aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/snippets/qtjavascript/integratingjswithcpp/qjsengine.cpp
blob: 9e022c01d33c05ad44621b581e206a583a847ca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

//![qjs-engine]

    QJSEngine engine;
    QJSValue object =  engine.newObject();
    object.setProperty("num", 42);
    QJSValue function = engine.evaluate("(o) => o.num *= 2 ");
    QJSValueList args = { object };
    QJSValue result = function.call(args);
    QJSValue expected = "84";
    Q_ASSERT(result.equals(expected) && !result.strictlyEquals(expected));

//![qjs-engine]