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
qjsvalue.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QJSVALUE_H
5#define QJSVALUE_H
6
7#include <QtQml/qtqmlglobal.h>
8#include <QtCore/qstring.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qmetatype.h>
11
13
14class QJSValue;
15class QJSEngine;
16class QVariant;
17class QObject;
18struct QMetaObject;
19class QDateTime;
21
22typedef QList<QJSValue> QJSValueList;
23namespace QV4 {
24 struct ExecutionEngine;
25}
26
28class QJSManagedValue;
29
30class Q_QML_EXPORT QJSValue
31{
32public:
35 UndefinedValue
36 };
37
48
51 RetainJSObjects
52 };
53
54public:
55 QJSValue(SpecialValue value = UndefinedValue);
56 ~QJSValue();
57 QJSValue(const QJSValue &other);
58
59 inline QJSValue(QJSValue && other) : d(other.d) { other.d = 0; }
61 { std::swap(d, other.d); return *this; }
62
63 QJSValue(bool value);
64 QJSValue(int value);
66 QJSValue(double value);
67 QJSValue(const QString &value);
69#ifndef QT_NO_CAST_FROM_ASCII
70 QT_ASCII_CAST_WARN QJSValue(const char *str);
71#endif
72
73 QJSValue &operator=(const QJSValue &other);
74
76 explicit QJSValue(QJSManagedValue &&value);
77
78 bool isBool() const;
79 bool isNumber() const;
80 bool isNull() const;
81 bool isString() const;
82 bool isUndefined() const;
83#if QT_DEPRECATED_SINCE(6, 9)
84 QT_DEPRECATED_VERSION_X_6_9("This might return unexpected results; consult documentation for more information")
85 bool isVariant() const;
86#endif
87 bool isQObject() const;
88 bool isQMetaObject() const;
89 bool isObject() const;
90 bool isDate() const;
91 bool isRegExp() const;
92 bool isArray() const;
93 bool isError() const;
94 bool isUrl() const;
95
96 QString toString() const;
97 double toNumber() const;
98 qint32 toInt() const;
99 quint32 toUInt() const;
100 bool toBool() const;
101
102 QVariant toVariant() const;
103 QVariant toVariant(ObjectConversionBehavior behavior) const;
104 QJSPrimitiveValue toPrimitive() const;
105
106 QObject *toQObject() const;
107 const QMetaObject *toQMetaObject() const;
108 QDateTime toDateTime() const;
109
110 bool equals(const QJSValue &other) const;
111 bool strictlyEquals(const QJSValue &other) const;
112
113 QJSValue prototype() const;
114 void setPrototype(const QJSValue &prototype);
115
116 QJSValue property(const QString &name) const;
117 void setProperty(const QString &name, const QJSValue &value);
118
119 bool hasProperty(const QString &name) const;
120 bool hasOwnProperty(const QString &name) const;
121
122 QJSValue property(quint32 arrayIndex) const;
123 void setProperty(quint32 arrayIndex, const QJSValue &value);
124
125 bool deleteProperty(const QString &name);
126
127 bool isCallable() const;
128 QJSValue call(const QJSValueList &args = QJSValueList()) const;
129 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList()) const;
130 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList()) const;
131
132 ErrorType errorType() const;
133
134private:
135 friend class QJSValuePrivate;
136 // force compile error, prevent QJSValue(bool) to be called
137 QJSValue(void *) = delete;
138
139 quint64 d;
140};
141
142#ifndef QT_NO_DATASTREAM
143Q_QML_EXPORT QDataStream &operator<<(QDataStream &, const QJSValue &);
144Q_QML_EXPORT QDataStream &operator>>(QDataStream &, QJSValue &);
145#endif
146
148
150
151#endif
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
\inmodule QtQml
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
@ RangeError
Definition qjsvalue.h:42
@ SyntaxError
Definition qjsvalue.h:44
@ ReferenceError
Definition qjsvalue.h:43
@ GenericError
Definition qjsvalue.h:40
@ EvalError
Definition qjsvalue.h:41
@ TypeError
Definition qjsvalue.h:45
@ NoError
Definition qjsvalue.h:39
SpecialValue
This enum is used to specify a single-valued type.
Definition qjsvalue.h:33
@ NullValue
Definition qjsvalue.h:34
QJSValue & operator=(QJSValue &&other)
Move-assigns other to this QJSValue object.
Definition qjsvalue.h:60
QJSValue(QJSValue &&other)
Move constructor.
Definition qjsvalue.h:59
ObjectConversionBehavior
This enum is used to specify how JavaScript objects and symbols without an equivalent native Qt type ...
Definition qjsvalue.h:49
@ ConvertJSObjects
Definition qjsvalue.h:50
Definition qlist.h:75
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
QString str
[2]
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Q_QML_EXPORT QDataStream & operator<<(QDataStream &, const QJSValue &)
Q_QML_EXPORT QDataStream & operator>>(QDataStream &, QJSValue &)
QList< QJSValue > QJSValueList
Definition qjsvalue.h:22
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1525
static bool isNumber(char s)
GLuint name
#define QT_DEPRECATED_VERSION_X_6_9(text)
#define QT_ASCII_CAST_WARN
unsigned int quint32
Definition qtypes.h:50
int qint32
Definition qtypes.h:49
unsigned long long quint64
Definition qtypes.h:61
unsigned int uint
Definition qtypes.h:34
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, JSToQVariantConversionBehavior conversionBehavior, V4ObjectSet *visitedObjects)
static int toInt(const QChar &qc, int R)
static bool isRegExp(ExecutionEngine *e, const QV4::Value *arg)
const char property[13]
Definition qwizard.cpp:101
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)
QJSValueList args
\inmodule QtCore
QT_BEGIN_NAMESPACE bool toBool(const QString &str)
Definition utils.h:14