Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant
4
5#ifndef QJSVALUE_H
6#define QJSVALUE_H
7
8#include <QtQml/qtqmlglobal.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qlist.h>
11#include <QtCore/qmetatype.h>
12
14
15class QJSValue;
16class QJSEngine;
17class QVariant;
18class QObject;
19struct QMetaObject;
20class QDateTime;
22
24namespace QV4 {
25 struct ExecutionEngine;
26}
27
29class QJSManagedValue;
30
31class Q_QML_EXPORT QJSValue
32{
33public:
34 enum SpecialValue {
35 NullValue,
36 UndefinedValue
37 };
38
39 enum ErrorType {
40 NoError,
41 GenericError,
42 EvalError,
43 RangeError,
44 ReferenceError,
45 SyntaxError,
46 TypeError,
47 URIError
48 };
49
50 enum ObjectConversionBehavior {
51 ConvertJSObjects,
52 RetainJSObjects
53 };
54
55public:
56 QJSValue(SpecialValue value = UndefinedValue);
57 ~QJSValue();
58 QJSValue(const QJSValue &other);
59
60 inline QJSValue(QJSValue && other) : d(other.d) { other.d = 0; }
61 inline QJSValue &operator=(QJSValue &&other)
62 { std::swap(d, other.d); return *this; }
63
64 QJSValue(bool value);
65 QJSValue(int value);
66 QJSValue(uint value);
67 QJSValue(double value);
68 QJSValue(const QString &value);
69 QJSValue(const QLatin1String &value);
70#ifndef QT_NO_CAST_FROM_ASCII
71 QT_ASCII_CAST_WARN QJSValue(const char *str);
72#endif
73
74 QJSValue &operator=(const QJSValue &other);
75
76 explicit QJSValue(QJSPrimitiveValue &&value);
77 explicit QJSValue(QJSManagedValue &&value);
78
79 bool isBool() const;
80 bool isNumber() const;
81 bool isNull() const;
82 bool isString() const;
83 bool isUndefined() const;
84#if QT_DEPRECATED_SINCE(6, 9)
85 QT_DEPRECATED_VERSION_X_6_9("This might return unexpected results; consult documentation for more information")
86 bool isVariant() const;
87#endif
88 bool isQObject() const;
89 bool isQMetaObject() const;
90 bool isObject() const;
91 bool isDate() const;
92 bool isRegExp() const;
93 bool isArray() const;
94 bool isError() const;
95 bool isUrl() const;
96
97 QString toString() const;
98 double toNumber() const;
99 qint32 toInt() const;
100 quint32 toUInt() const;
101 bool toBool() const;
102
103 QVariant toVariant() const;
104 QVariant toVariant(ObjectConversionBehavior behavior) const;
105 QJSPrimitiveValue toPrimitive() const;
106
107 QObject *toQObject() const;
108 const QMetaObject *toQMetaObject() const;
109 QDateTime toDateTime() const;
110
111 bool equals(const QJSValue &other) const;
112 bool strictlyEquals(const QJSValue &other) const;
113
114 QJSValue prototype() const;
115 void setPrototype(const QJSValue &prototype);
116
117 QJSValue property(const QString &name) const;
118 void setProperty(const QString &name, const QJSValue &value);
119
120 bool hasProperty(const QString &name) const;
121 bool hasOwnProperty(const QString &name) const;
122
123 QJSValue property(quint32 arrayIndex) const;
124 void setProperty(quint32 arrayIndex, const QJSValue &value);
125
126 bool deleteProperty(const QString &name);
127
128 bool isCallable() const;
129 QJSValue call(const QJSValueList &args = QJSValueList()) const;
130 QJSValue callWithInstance(const QJSValue &instance, const QJSValueList &args = QJSValueList()) const;
131 QJSValue callAsConstructor(const QJSValueList &args = QJSValueList()) const;
132
133 ErrorType errorType() const;
134
135private:
136 friend class QJSValuePrivate;
137 // force compile error, prevent QJSValue(bool) to be called
138 QJSValue(void *) = delete;
139
140 quint64 d;
141};
142
143#ifndef QT_NO_DATASTREAM
144Q_QML_EXPORT QDataStream &operator<<(QDataStream &, const QJSValue &);
145Q_QML_EXPORT QDataStream &operator>>(QDataStream &, QJSValue &);
146#endif
147
148QT_END_NAMESPACE
149
150Q_DECLARE_METATYPE(QJSValue)
151
152#endif
\inmodule QtCore\reentrant
Definition qdatastream.h:50
\inmodule QtCore
Definition qhash.h:843
friend class QJSEngine
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:32
QSettings * instance() const
QPointer< QSettings > settings
QQmlSettingsLabs * q_ptr
QVariant readProperty(const QMetaProperty &property) const
QHash< const char *, QVariant > changedProperties
static constexpr auto settingsWriteDelay
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
QList< QJSValue > QJSValueList
Definition qjsvalue.h:23
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)