The QJSPrimitiveValue class operates on primitive types in JavaScript semantics. 更多...
头: | #include <QJSPrimitiveValue> |
CMake: |
find_package(Qt6 COMPONENTS Qml REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
Since: | Qt 6.1 |
enum | Type { Undefined, Null, Boolean, Integer, Double, String } |
QJSPrimitiveValue (QString value ) | |
QJSPrimitiveValue (double value ) | |
QJSPrimitiveValue (int value ) | |
QJSPrimitiveValue (bool value ) | |
QJSPrimitiveValue (QJSPrimitiveNull null ) | |
QJSPrimitiveValue (QJSPrimitiveUndefined undefined ) | |
QJSPrimitiveValue () | |
bool | equals (const QJSPrimitiveValue & other ) const |
bool | strictlyEquals (const QJSPrimitiveValue & other ) const |
bool | toBoolean () const |
double | toDouble () const |
int | toInteger () const |
QString | toString () const |
QJSPrimitiveValue::Type | type () const |
bool | operator!= (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
QJSPrimitiveValue | operator* (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
QJSPrimitiveValue | operator+ (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
QJSPrimitiveValue | operator- (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
QJSPrimitiveValue | operator/ (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
bool | operator< (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
bool | operator<= (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
bool | operator== (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
bool | operator> (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
bool | operator>= (const QJSPrimitiveValue & lhs , const QJSPrimitiveValue & rhs ) |
QJSPrimitiveValue supports most of the primitive types defined in the ECMA-262 standard, in particular Undefined, Boolean, Number, and String. Additionally, you can store a JavaScript null in a QJSPrimitiveValue and as a special case of Number, you can store an integer value.
All those values are stored immediately, without interacting with the JavaScript heap. Therefore, you can pass QJSPrimitiveValues between different JavaScript engines. In contrast to QJSManagedValue , there is also no danger in destroying a QJSPrimitiveValue from a different thread than it was created in. On the flip side, QJSPrimitiveValue does not hold a reference to any JavaScript engine.
QJSPrimitiveValue implements the JavaScript arithmetic and comparison operators on the supported types in JavaScript semantics. Types are coerced like the JavaScript engine would coerce them if the operators were written in a JavaScript expression.
The JavaScript Symbol type is not supported as it is of very limited utility regarding arithmetic and comparison operators, the main purpose of QJSPrimitiveValue. In particular, it causes an exception whenever you try to coerce it to a number or a string, and we cannot throw exceptions without a JavaScript Engine.
This enum speicifies the types a QJSPrimitiveValue might contain.
常量 | 值 | 描述 |
---|---|---|
QJSPrimitiveValue::Undefined
|
0
|
The JavaScript Undefined value. |
QJSPrimitiveValue::Null
|
1
|
The JavaScript null value. This is in fact not a separate JavaScript type but a special value of the Object type. As it is very common and storable without JavaScript engine, it is still supported. |
QJSPrimitiveValue::Boolean
|
2
|
A JavaScript Boolean value. |
QJSPrimitiveValue::Integer
|
3
|
An integer. This is a special case of the JavaScript Number type. JavaScript does not have an actual integer type, but the ECMA-262 standard contains rules on how to transform a Number in order to prepare it for certain operators that only make sense on integers, in particular the bit shift operators. QJSPrimitiveValue 's Integer type represents the result of such a transformation. |
QJSPrimitiveValue::Double
|
4
|
A JavaScript Number value. |
QJSPrimitiveValue::String
|
5
|
A JavaScript String value. |
Creates a QJSPrimitiveValue of value value and type String.
Creates a QJSPrimitiveValue of value value and type Double.
Creates a QJSPrimitiveValue of value value and type Integer.
Creates a QJSPrimitiveValue of value value and type Boolean.
Creates a QJSPrimitiveValue of value null and type Null.
Creates a QJSPrimitiveValue of value undefined and type Undefined.
Creates a QJSPrimitiveValue of type Undefined.
Performs the JavaScript '==' operation on this QJSPrimitiveValue and other , and returns the result.
Performs the JavaScript '===' operation on this QJSPrimitiveValue and other , and returns the result.
Returns the value coerced a boolean by JavaScript rules.
Returns the value coerced to a JavaScript Number by JavaScript rules.
Returns the value coerced to an integral 32bit number by the rules JavaScript would apply when preparing it for a bit shift operation.
Returns the value coerced to a JavaScript String by JavaScript rules.
Returns the type of the QJSPrimitiveValue .
[since 6.1]
bool
operator!=
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '!==' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
QJSPrimitiveValue
operator*
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '*' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
QJSPrimitiveValue
operator+
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Perfoms the JavaScript '+' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
QJSPrimitiveValue
operator-
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '-' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
QJSPrimitiveValue
operator/
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '/' operation between lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
bool
operator<
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '<' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
bool
operator<=
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '<=' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
bool
operator==
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '===' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
bool
operator>
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '>' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。
[since 6.1]
bool
operator>=
(const
QJSPrimitiveValue
&
lhs
, const
QJSPrimitiveValue
&
rhs
)
Performs the JavaScript '>=' operation on lhs and rhs , and returns the result.
该函数在 Qt 6.1 引入。