Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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");
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");
15 managed.property("f");
16 qDebug() << engine.hasError(); // prints true
17
20
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
bool hasError() const
Returns true if the last JavaScript execution resulted in an exception or if throwError() was called.
QJSValue catchError()
If an exception is currently pending, catches it and returns it as a QJSValue.
QJSValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1, QStringList *exceptionStackTrace=nullptr)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
\inmodule QtQml
QJSValue property(const QString &name) const
Returns the property name of this QJSManagedValue.
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
qint32 toInt() const
Returns the signed 32-bit integer value of this QJSValue, using the conversion rules described in \l{...
Definition qjsvalue.cpp:566
QJSValue property(const QString &name) const
Returns the value of this QJSValue's property with the given name.
QJSValue error
qDebug()<< engine.hasError()
[1]
QJSManagedValue managed(std::move(val), &engine)
QJSEngine engine
[qjs-engine-example]
GLuint GLfloat * val
#define Q_ASSERT(cond)
Definition qrandom.cpp:47