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
qjsmanagedvalue.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QJSMANAGEDVALUE_H
5#define QJSMANAGEDVALUE_H
6
7#include <QtQml/qtqmlglobal.h>
8#include <QtQml/qjsprimitivevalue.h>
9#include <QtQml/qjsvalue.h>
10
12
13namespace QV4 {
14struct Value;
15struct ExecutionEngine;
16}
17
18class QJSEngine;
19class Q_QML_EXPORT QJSManagedValue
20{
21 Q_DISABLE_COPY(QJSManagedValue)
22public:
32
33 QJSManagedValue() = default;
37 QJSManagedValue(const QString &string, QJSEngine *engine);
38
42
43 bool equals(const QJSManagedValue &other) const;
44 bool strictlyEquals(const QJSManagedValue &other) const;
45
46 QJSEngine *engine() const;
47
48 QJSManagedValue prototype() const;
49 void setPrototype(const QJSManagedValue &prototype);
50
51 Type type() const;
52
53 // Compatibility with QJSValue
54 bool isUndefined() const { return type() == Undefined; }
55 bool isBoolean() const { return type() == Boolean; }
56 bool isNumber() const { return type() == Number; }
57 bool isString() const { return type() == String; }
58 bool isObject() const { return type() == Object; }
59 bool isSymbol() const { return type() == Symbol; }
60 bool isFunction() const { return type() == Function; }
61
62 // Special case of Number
63 bool isInteger() const;
64
65 // Selected special cases of Object
66 bool isNull() const;
67 bool isRegularExpression() const;
68 bool isArray() const;
69 bool isUrl() const;
70 bool isVariant() const;
71 bool isQObject() const;
72 bool isQMetaObject() const;
73 bool isDate() const;
74 bool isError() const;
75 bool isJsMetaType() const;
76
77 // Native type transformations
78 QString toString() const;
79 double toNumber() const;
80 bool toBoolean() const;
81
82 // Variant-like type transformations
83 QJSPrimitiveValue toPrimitive() const;
84 QJSValue toJSValue() const;
85 QVariant toVariant() const;
86
87 // Special cases
88 int toInteger() const;
89 QRegularExpression toRegularExpression() const;
90 QUrl toUrl() const;
91 QObject *toQObject() const;
92 const QMetaObject *toQMetaObject() const;
93 QDateTime toDateTime() const;
94
95 // Properties of objects
96 bool hasProperty(const QString &name) const;
97 bool hasOwnProperty(const QString &name) const;
98 QJSValue property(const QString &name) const;
99 void setProperty(const QString &name, const QJSValue &value);
100 bool deleteProperty(const QString &name);
101
102 // ### Qt 7 use qsizetype instead.
103 // Array indexing
104 bool hasProperty(quint32 arrayIndex) const;
105 bool hasOwnProperty(quint32 arrayIndex) const;
106 QJSValue property(quint32 arrayIndex) const;
107 void setProperty(quint32 arrayIndex, const QJSValue &value);
108 bool deleteProperty(quint32 arrayIndex);
109
110 // Calling functions
111 QJSValue call(const QJSValueList &arguments = {}) const;
112 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &arguments = {}) const;
113 QJSValue callAsConstructor(const QJSValueList &arguments = {}) const;
114
115 // JavaScript metatypes
116 QJSManagedValue jsMetaType() const;
117 QStringList jsMetaMembers() const;
118 QJSManagedValue jsMetaInstantiate(const QJSValueList &values = {}) const;
119
120private:
121 friend class QJSValue;
122 friend class QJSEngine;
123
125 QV4::Value *d = nullptr;
126};
127
129
130#endif
Definition main.cpp:8
\inmodule QtCore\reentrant
Definition qdatetime.h:283
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
\inmodule QtQml
bool isUndefined() const
Returns true if the type of this QJSManagedValue is undefined, or false otherwise.
QJSManagedValue()=default
Creates a QJSManagedValue that represents the JavaScript undefined value.
bool isBoolean() const
Returns true if the type of this QJSManagedValue is boolean, or false otherwise.
bool isNumber() const
Returns true if the type of this QJSManagedValue is number, or false otherwise.
bool isObject() const
Returns true if the type of this QJSManagedValue is object, or false otherwise.
bool isString() const
Returns true if the type of this QJSManagedValue is string, or false otherwise.
bool isFunction() const
Returns true if the type of this QJSManagedValue is function, false otherwise.
bool isSymbol() const
Returns true if the type of this QJSManagedValue is symbol, or false otherwise.
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
Definition qlist.h:75
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore \reentrant
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
QList< QVariant > arguments
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLsizei GLsizei GLint * values
[15]
GLenum type
GLuint name
unsigned int quint32
Definition qtypes.h:50
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
const char property[13]
Definition qwizard.cpp:101
QVariant variant
[1]
QSharedPointer< T > other(t)
[5]
char * toString(const MyType &t)
[31]
args<< 1<< 2;QJSValue threeAgain=fun.call(args);QString fileName="helloworld.qs";QFile scriptFile(fileName);if(!scriptFile.open(QIODevice::ReadOnly)) QTextStream stream(&scriptFile);QString contents=stream.readAll();scriptFile.close();myEngine.evaluate(contents, fileName);myEngine.globalObject().setProperty("myNumber", 123);...QJSValue myNumberPlusOne=myEngine.evaluate("myNumber + 1");QJSValue result=myEngine.evaluate(...);if(result.isError()) qDebug()<< "Uncaught exception at line"<< result.property("lineNumber").toInt()<< ":"<< result.toString();QPushButton *button=new QPushButton;QJSValue scriptButton=myEngine.newQObject(button);myEngine.globalObject().setProperty("button", scriptButton);myEngine.evaluate("button.checkable = true");qDebug()<< scriptButton.property("checkable").toBool();scriptButton.property("show").call();QJSEngine engine;QObject *myQObject=new QObject();myQObject- setProperty)("dynamicProperty", 3)
QJSEngine engine
[0]
\inmodule QtCore
Definition moc.h:23