Qt 6.x
The Qt SDK
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
23namespace QV4 {
24 struct ExecutionEngine;
25}
26
28class QJSManagedValue;
29
30class Q_QML_EXPORT QJSValue
31{
32public:
35 UndefinedValue
36 };
37
38 enum ErrorType {
46 URIError
47 };
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 bool isVariant() const;
84 bool isQObject() const;
85 bool isQMetaObject() const;
86 bool isObject() const;
87 bool isDate() const;
88 bool isRegExp() const;
89 bool isArray() const;
90 bool isError() const;
91 bool isUrl() const;
92
93 QString toString() const;
94 double toNumber() const;
95 qint32 toInt() const;
96 quint32 toUInt() const;
97 bool toBool() const;
98
99 QVariant toVariant() const;
100 QVariant toVariant(ObjectConversionBehavior behavior) const;
101 QJSPrimitiveValue toPrimitive() const;
102
103 QObject *toQObject() const;
104 const QMetaObject *toQMetaObject() const;
105 QDateTime toDateTime() const;
106
107 bool equals(const QJSValue &other) const;
108 bool strictlyEquals(const QJSValue &other) const;
109
110 QJSValue prototype() const;
111 void setPrototype(const QJSValue &prototype);
112
113 QJSValue property(const QString &name) const;
114 void setProperty(const QString &name, const QJSValue &value);
115
116 bool hasProperty(const QString &name) const;
117 bool hasOwnProperty(const QString &name) const;
118
119 QJSValue property(quint32 arrayIndex) const;
120 void setProperty(quint32 arrayIndex, const QJSValue &value);
121
122 bool deleteProperty(const QString &name);
123
124 bool isCallable() const;
125 QJSValue call(const QJSValueList &args = QJSValueList()) const;
126 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList()) const;
127 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList()) const;
128
129 ErrorType errorType() const;
130
131private:
132 friend class QJSValuePrivate;
133 // force compile error, prevent QJSValue(bool) to be called
134 QJSValue(void *) = delete;
135
136 quint64 d;
137};
138
139#ifndef QT_NO_DATASTREAM
140Q_QML_EXPORT QDataStream &operator<<(QDataStream &, const QJSValue &);
141Q_QML_EXPORT QDataStream &operator>>(QDataStream &, QJSValue &);
142#endif
143
145
147
148#endif
\inmodule QtCore\reentrant
Definition qdatastream.h:30
\inmodule QtCore\reentrant
Definition qdatetime.h:257
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:74
\inmodule QtCore
Definition qobject.h:90
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qvariant.h:64
QString str
[2]
object setProperty("down", true)
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
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:1504
static bool isNumber(char s)
GLuint name
#define QT_ASCII_CAST_WARN
unsigned int quint32
Definition qtypes.h:45
int qint32
Definition qtypes.h:44
unsigned long long quint64
Definition qtypes.h:56
unsigned int uint
Definition qtypes.h:29
static QVariant toVariant(const QV4::Value &value, QMetaType typeHint, bool createJSValueForObjectsAndSymbols, 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]
QJSValueList args
\inmodule QtCore
QT_BEGIN_NAMESPACE bool toBool(const QString &str)
Definition utils.h:14