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
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtQml>
5
6int main(int argc, char *argv[])
7{
8 QCoreApplication app(argc, argv);
11 engine.globalObject().setProperty("foo", 123);
12 qDebug() << "foo times two is:" << engine.evaluate("foo * 2").toNumber();
14 return 0;
15}
16
\inmodule QtCore
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
QJSValue globalObject() const
Returns this engine's Global Object.
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...
double toNumber() const
Returns the number value of this QJSValue, as defined in \l{ECMA-262} section 9.3,...
Definition qjsvalue.cpp:526
void setProperty(const QString &name, const QJSValue &value)
Sets the value of this QJSValue's property with the given name to the given value.
int main()
[0]
#define qDebug
[1]
Definition qlogging.h:164
QApplication app(argc, argv)
[0]
QJSEngine engine
[0]