Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
exampleqjsengine.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//![qjs-engine-example]
5
7 // We create an object with a read-only property whose getter throws an exception
8 auto val = engine.evaluate("let o = { get f() {throw 42;} }; o");
9 val.property("f");
10 qDebug() << engine.hasError(); // prints false
11
12 // This time, we construct a QJSManagedValue before accessing the property
13 val = engine.evaluate("let o = { get f() {throw 42;} }; o");
14 QJSManagedValue managed(std::move(val), &engine);
15 managed.property("f");
16 qDebug() << engine.hasError(); // prints true
17
18 QJSValue error = engine.catchError();
19 Q_ASSERT(error.toInt(), 42);
20
21//![qjs-engine-example]
QJSValue error
QJSManagedValue managed(std::move(val), &engine)
auto val
Q_ASSERT(error.toInt(), 42)
QJSEngine engine
[0]