[][src]Struct qt_qml::QJSValue

#[repr(C)]pub struct QJSValue { /* fields omitted */ }

QJSValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object and Array types. Additionally, built-in support is provided for Qt/C++ types such as QVariant and QObject.

C++ class: QJSValue.

C++ documentation:

QJSValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object and Array types. Additionally, built-in support is provided for Qt/C++ types such as QVariant and QObject.

For the object-based types (including Date and RegExp), use the newT() functions in QJSEngine (e.g. QJSEngine::newObject()) to create a QJSValue of the desired type. For the primitive types, use one of the QJSValue constructor overloads. For other types, e.g. registered gadget types such as QPoint, you can use QJSEngine::toScriptValue.

The methods named isT() (e.g. isBool(), isUndefined()) can be used to test if a value is of a certain type. The methods named toT() (e.g. toBool(), toString()) can be used to convert a QJSValue to another type. You can also use the generic qjsvalue_cast() function.

Object values have zero or more properties which are themselves QJSValues. Use setProperty() to set a property of an object, and call property() to retrieve the value of a property.

QJSEngine myEngine; QJSValue myObject = myEngine.newObject(); QJSValue myOtherObject = myEngine.newObject(); myObject.setProperty("myChild", myOtherObject); myObject.setProperty("name", "John Doe");

If you want to iterate over the properties of a script object, use the QJSValueIterator class.

Object values have an internal prototype property, which can be accessed with prototype() and setPrototype().

Function objects (objects for which isCallable()) returns true) can be invoked by calling call(). Constructor functions can be used to construct new objects by calling callAsConstructor().

Use equals() or strictlyEquals() to compare a QJSValue to another.

Note that a QJSValue for which isObject() is true only carries a reference to an actual object; copying the QJSValue will only copy the object reference, not the object itself. If you want to clone an object (i.e. copy an object's properties to another object), you can do so with the help of a for-in statement in script code, or QJSValueIterator in C++.

Methods

impl QJSValue[src]

pub unsafe fn call_1a(
    &self,
    args: impl CastInto<Ref<QListOfQJSValue>>
) -> CppBox<QJSValue>
[src]

Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObject() as the "this"-object. Returns the value returned from the function.

Calls C++ function: QJSValue QJSValue::call(const QList<QJSValue>& args = …).

C++ documentation:

Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObject() as the "this"-object. Returns the value returned from the function.

If this QJSValue is not callable, call() does nothing and returns an undefined QJSValue.

Calling call() can cause an exception to occur in the script engine; in that case, call() returns the value that was thrown (typically an Error object). You can call isError() on the return value to determine whether an exception occurred.

See also isCallable(), callWithInstance(), and callAsConstructor().

pub unsafe fn call_0a(&self) -> CppBox<QJSValue>[src]

Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObject() as the "this"-object. Returns the value returned from the function.

Calls C++ function: QJSValue QJSValue::call().

C++ documentation:

Calls this QJSValue as a function, passing args as arguments to the function, and using the globalObject() as the "this"-object. Returns the value returned from the function.

If this QJSValue is not callable, call() does nothing and returns an undefined QJSValue.

Calling call() can cause an exception to occur in the script engine; in that case, call() returns the value that was thrown (typically an Error object). You can call isError() on the return value to determine whether an exception occurred.

See also isCallable(), callWithInstance(), and callAsConstructor().

pub unsafe fn call_as_constructor_1a(
    &self,
    args: impl CastInto<Ref<QListOfQJSValue>>
) -> CppBox<QJSValue>
[src]

Creates a new Object and calls this QJSValue as a constructor, using the created object as the `this' object and passing args as arguments. If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

Calls C++ function: QJSValue QJSValue::callAsConstructor(const QList<QJSValue>& args = …).

C++ documentation:

Creates a new Object and calls this QJSValue as a constructor, using the created object as the `this' object and passing args as arguments. If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

If this QJSValue is not a function, callAsConstructor() does nothing and returns an undefined QJSValue.

Calling this function can cause an exception to occur in the script engine; in that case, the value that was thrown (typically an Error object) is returned. You can call isError() on the return value to determine whether an exception occurred.

See also call() and QJSEngine::newObject().

pub unsafe fn call_as_constructor_0a(&self) -> CppBox<QJSValue>[src]

Creates a new Object and calls this QJSValue as a constructor, using the created object as the `this' object and passing args as arguments. If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

Calls C++ function: QJSValue QJSValue::callAsConstructor().

C++ documentation:

Creates a new Object and calls this QJSValue as a constructor, using the created object as the `this' object and passing args as arguments. If the return value from the constructor call is an object, then that object is returned; otherwise the default constructed object is returned.

If this QJSValue is not a function, callAsConstructor() does nothing and returns an undefined QJSValue.

Calling this function can cause an exception to occur in the script engine; in that case, the value that was thrown (typically an Error object) is returned. You can call isError() on the return value to determine whether an exception occurred.

See also call() and QJSEngine::newObject().

pub unsafe fn call_with_instance_2a(
    &self,
    instance: impl CastInto<Ref<QJSValue>>,
    args: impl CastInto<Ref<QListOfQJSValue>>
) -> CppBox<QJSValue>
[src]

Calls this QJSValue as a function, using instance as the `this' object in the function call, and passing args as arguments to the function. Returns the value returned from the function.

Calls C++ function: QJSValue QJSValue::callWithInstance(const QJSValue& instance, const QList<QJSValue>& args = …).

C++ documentation:

Calls this QJSValue as a function, using instance as the `this' object in the function call, and passing args as arguments to the function. Returns the value returned from the function.

If this QJSValue is not a function, call() does nothing and returns an undefined QJSValue.

Note that if instance is not an object, the global object (see QJSEngine::globalObject()) will be used as the `this' object.

Calling call() can cause an exception to occur in the script engine; in that case, call() returns the value that was thrown (typically an Error object). You can call isError() on the return value to determine whether an exception occurred.

See also call().

pub unsafe fn call_with_instance_1a(
    &self,
    instance: impl CastInto<Ref<QJSValue>>
) -> CppBox<QJSValue>
[src]

Calls this QJSValue as a function, using instance as the `this' object in the function call, and passing args as arguments to the function. Returns the value returned from the function.

Calls C++ function: QJSValue QJSValue::callWithInstance(const QJSValue& instance).

C++ documentation:

Calls this QJSValue as a function, using instance as the `this' object in the function call, and passing args as arguments to the function. Returns the value returned from the function.

If this QJSValue is not a function, call() does nothing and returns an undefined QJSValue.

Note that if instance is not an object, the global object (see QJSEngine::globalObject()) will be used as the `this' object.

Calling call() can cause an exception to occur in the script engine; in that case, call() returns the value that was thrown (typically an Error object). You can call isError() on the return value to determine whether an exception occurred.

See also call().

pub unsafe fn copy_from(
    &self,
    other: impl CastInto<Ref<QJSValue>>
) -> Ref<QJSValue>
[src]

Assigns the other value to this QJSValue.

Calls C++ function: QJSValue& QJSValue::operator=(const QJSValue& other).

C++ documentation:

Assigns the other value to this QJSValue.

Note that if other is an object (isObject() returns true), only a reference to the underlying object will be assigned; the object itself will not be copied.

pub unsafe fn delete_property(&self, name: impl CastInto<Ref<QString>>) -> bool[src]

Attempts to delete this object's property of the given name. Returns true if the property was deleted, otherwise returns false.

Calls C++ function: bool QJSValue::deleteProperty(const QString& name).

C++ documentation:

Attempts to delete this object's property of the given name. Returns true if the property was deleted, otherwise returns false.

The behavior of this function is consistent with the JavaScript delete operator. In particular:

  • Non-configurable properties cannot be deleted.
  • This function will return true even if this object doesn't have a property of the given name (i.e., non-existent properties are "trivially deletable").
  • If this object doesn't have an own property of the given name, but an object in the prototype() chain does, the prototype object's property is not deleted, and this function returns true.

See also setProperty() and hasOwnProperty().

pub unsafe fn engine(&self) -> QPtr<QJSEngine>[src]

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Calls C++ function: QJSEngine* QJSValue::engine() const.

C++ documentation:

This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

Returns the QJSEngine that created this QJSValue, or 0 if this QJSValue is invalid or the value is not associated with a particular engine.

pub unsafe fn equals(&self, other: impl CastInto<Ref<QJSValue>>) -> bool[src]

Returns true if this QJSValue is equal to other, otherwise returns false. The comparison follows the behavior described in ECMA-262 section 11.9.3, "The Abstract Equality Comparison Algorithm".

Calls C++ function: bool QJSValue::equals(const QJSValue& other) const.

C++ documentation:

Returns true if this QJSValue is equal to other, otherwise returns false. The comparison follows the behavior described in ECMA-262 section 11.9.3, "The Abstract Equality Comparison Algorithm".

This function can return true even if the type of this QJSValue is different from the type of the other value; i.e. the comparison is not strict. For example, comparing the number 9 to the string "9" returns true; comparing an undefined value to a null value returns true; comparing a Number object whose primitive value is 6 to a String object whose primitive value is "6" returns true; and comparing the number 1 to the boolean value true returns true. If you want to perform a comparison without such implicit value conversion, use strictlyEquals().

Note that if this QJSValue or the other value are objects, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also strictlyEquals().

pub unsafe fn error_type(&self) -> ErrorType[src]

This is supported on cpp_lib_version="5.13.0" or cpp_lib_version="5.12.2" or cpp_lib_version="5.14.0" only.

Returns the error type this QJSValue represents if it is an Error object. Otherwise, returns NoError."

Calls C++ function: QJSValue::ErrorType QJSValue::errorType() const.

C++ documentation:

Returns the error type this QJSValue represents if it is an Error object. Otherwise, returns NoError."

This function was introduced in Qt 5.12.

See also isError() and QJSEngine - Script Exceptions.

pub unsafe fn has_own_property(&self, name: impl CastInto<Ref<QString>>) -> bool[src]

Returns true if this object has an own (not prototype-inherited) property of the given name, otherwise returns false.

Calls C++ function: bool QJSValue::hasOwnProperty(const QString& name) const.

C++ documentation:

Returns true if this object has an own (not prototype-inherited) property of the given name, otherwise returns false.

See also property() and hasProperty().

pub unsafe fn has_property(&self, name: impl CastInto<Ref<QString>>) -> bool[src]

Returns true if this object has a property of the given name, otherwise returns false.

Calls C++ function: bool QJSValue::hasProperty(const QString& name) const.

C++ documentation:

Returns true if this object has a property of the given name, otherwise returns false.

See also property() and hasOwnProperty().

pub unsafe fn is_array(&self) -> bool[src]

Returns true if this QJSValue is an object of the Array class; otherwise returns false.

Calls C++ function: bool QJSValue::isArray() const.

C++ documentation:

Returns true if this QJSValue is an object of the Array class; otherwise returns false.

See also QJSEngine::newArray().

pub unsafe fn is_bool(&self) -> bool[src]

Returns true if this QJSValue is of the primitive type Boolean; otherwise returns false.

Calls C++ function: bool QJSValue::isBool() const.

C++ documentation:

Returns true if this QJSValue is of the primitive type Boolean; otherwise returns false.

See also toBool().

pub unsafe fn is_callable(&self) -> bool[src]

Returns true if this QJSValue can be called a function, otherwise returns false.

Calls C++ function: bool QJSValue::isCallable() const.

C++ documentation:

Returns true if this QJSValue can be called a function, otherwise returns false.

See also call().

pub unsafe fn is_date(&self) -> bool[src]

Returns true if this QJSValue is an object of the Date class; otherwise returns false.

Calls C++ function: bool QJSValue::isDate() const.

C++ documentation:

Returns true if this QJSValue is an object of the Date class; otherwise returns false.

pub unsafe fn is_error(&self) -> bool[src]

Returns true if this QJSValue is an object of the Error class; otherwise returns false.

Calls C++ function: bool QJSValue::isError() const.

C++ documentation:

Returns true if this QJSValue is an object of the Error class; otherwise returns false.

See also errorType() and QJSEngine - Script Exceptions.

pub unsafe fn is_null(&self) -> bool[src]

Returns true if this QJSValue is of the primitive type Null; otherwise returns false.

Calls C++ function: bool QJSValue::isNull() const.

C++ documentation:

Returns true if this QJSValue is of the primitive type Null; otherwise returns false.

pub unsafe fn is_number(&self) -> bool[src]

Returns true if this QJSValue is of the primitive type Number; otherwise returns false.

Calls C++ function: bool QJSValue::isNumber() const.

C++ documentation:

Returns true if this QJSValue is of the primitive type Number; otherwise returns false.

See also toNumber().

pub unsafe fn is_object(&self) -> bool[src]

Returns true if this QJSValue is of the Object type; otherwise returns false.

Calls C++ function: bool QJSValue::isObject() const.

C++ documentation:

Returns true if this QJSValue is of the Object type; otherwise returns false.

Note that function values, variant values, and QObject values are objects, so this function returns true for such values.

See also QJSEngine::newObject().

pub unsafe fn is_q_meta_object(&self) -> bool[src]

Returns true if this QJSValue is a QMetaObject; otherwise returns false.

Calls C++ function: bool QJSValue::isQMetaObject() const.

C++ documentation:

Returns true if this QJSValue is a QMetaObject; otherwise returns false.

This function was introduced in Qt 5.8.

See also toQMetaObject() and QJSEngine::newQMetaObject().

pub unsafe fn is_q_object(&self) -> bool[src]

Returns true if this QJSValue is a QObject; otherwise returns false.

Calls C++ function: bool QJSValue::isQObject() const.

C++ documentation:

Returns true if this QJSValue is a QObject; otherwise returns false.

Note: This function returns true even if the QObject that this QJSValue wraps has been deleted.

See also toQObject() and QJSEngine::newQObject().

pub unsafe fn is_reg_exp(&self) -> bool[src]

Returns true if this QJSValue is an object of the RegExp class; otherwise returns false.

Calls C++ function: bool QJSValue::isRegExp() const.

C++ documentation:

Returns true if this QJSValue is an object of the RegExp class; otherwise returns false.

pub unsafe fn is_string(&self) -> bool[src]

Returns true if this QJSValue is of the primitive type String; otherwise returns false.

Calls C++ function: bool QJSValue::isString() const.

C++ documentation:

Returns true if this QJSValue is of the primitive type String; otherwise returns false.

See also toString().

pub unsafe fn is_undefined(&self) -> bool[src]

Returns true if this QJSValue is of the primitive type Undefined; otherwise returns false.

Calls C++ function: bool QJSValue::isUndefined() const.

C++ documentation:

Returns true if this QJSValue is of the primitive type Undefined; otherwise returns false.

pub unsafe fn is_variant(&self) -> bool[src]

Returns true if this QJSValue is a variant value; otherwise returns false.

Calls C++ function: bool QJSValue::isVariant() const.

C++ documentation:

Returns true if this QJSValue is a variant value; otherwise returns false.

See also toVariant().

pub unsafe fn from_special_value(value: SpecialValue) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a special value.

Calls C++ function: [constructor] void QJSValue::QJSValue(QJSValue::SpecialValue value = …).

C++ documentation:

Constructs a new QJSValue with a special value.

pub unsafe fn from_bool(value: bool) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a boolean value.

Calls C++ function: [constructor] void QJSValue::QJSValue(bool value).

C++ documentation:

Constructs a new QJSValue with a boolean value.

pub unsafe fn from_int(value: c_int) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a number value.

Calls C++ function: [constructor] void QJSValue::QJSValue(int value).

C++ documentation:

Constructs a new QJSValue with a number value.

pub unsafe fn from_uint(value: c_uint) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a number value.

Calls C++ function: [constructor] void QJSValue::QJSValue(unsigned int value).

C++ documentation:

Constructs a new QJSValue with a number value.

pub unsafe fn from_double(value: c_double) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a number value.

Calls C++ function: [constructor] void QJSValue::QJSValue(double value).

C++ documentation:

Constructs a new QJSValue with a number value.

pub unsafe fn from_q_string(
    value: impl CastInto<Ref<QString>>
) -> CppBox<QJSValue>
[src]

Constructs a new QJSValue with a string value.

Calls C++ function: [constructor] void QJSValue::QJSValue(const QString& value).

C++ documentation:

Constructs a new QJSValue with a string value.

pub unsafe fn from_q_latin1_string(
    value: impl CastInto<Ref<QLatin1String>>
) -> CppBox<QJSValue>
[src]

Constructs a new QJSValue with a string value.

Calls C++ function: [constructor] void QJSValue::QJSValue(const QLatin1String& value).

C++ documentation:

Constructs a new QJSValue with a string value.

pub unsafe fn from_char(str: *const c_char) -> CppBox<QJSValue>[src]

Constructs a new QJSValue with a string value.

Calls C++ function: [constructor] void QJSValue::QJSValue(const char* str).

C++ documentation:

Constructs a new QJSValue with a string value.

pub unsafe fn new() -> CppBox<QJSValue>[src]

QJSValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object and Array types. Additionally, built-in support is provided for Qt/C++ types such as QVariant and QObject.

Calls C++ function: [constructor] void QJSValue::QJSValue().

C++ documentation:

QJSValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object and Array types. Additionally, built-in support is provided for Qt/C++ types such as QVariant and QObject.

For the object-based types (including Date and RegExp), use the newT() functions in QJSEngine (e.g. QJSEngine::newObject()) to create a QJSValue of the desired type. For the primitive types, use one of the QJSValue constructor overloads. For other types, e.g. registered gadget types such as QPoint, you can use QJSEngine::toScriptValue.

The methods named isT() (e.g. isBool(), isUndefined()) can be used to test if a value is of a certain type. The methods named toT() (e.g. toBool(), toString()) can be used to convert a QJSValue to another type. You can also use the generic qjsvalue_cast() function.

Object values have zero or more properties which are themselves QJSValues. Use setProperty() to set a property of an object, and call property() to retrieve the value of a property.

QJSEngine myEngine; QJSValue myObject = myEngine.newObject(); QJSValue myOtherObject = myEngine.newObject(); myObject.setProperty("myChild", myOtherObject); myObject.setProperty("name", "John Doe");

If you want to iterate over the properties of a script object, use the QJSValueIterator class.

Object values have an internal prototype property, which can be accessed with prototype() and setPrototype().

Function objects (objects for which isCallable()) returns true) can be invoked by calling call(). Constructor functions can be used to construct new objects by calling callAsConstructor().

Use equals() or strictlyEquals() to compare a QJSValue to another.

Note that a QJSValue for which isObject() is true only carries a reference to an actual object; copying the QJSValue will only copy the object reference, not the object itself. If you want to clone an object (i.e. copy an object's properties to another object), you can do so with the help of a for-in statement in script code, or QJSValueIterator in C++.

pub unsafe fn new_copy(other: impl CastInto<Ref<QJSValue>>) -> CppBox<QJSValue>[src]

Constructs a new QJSValue that is a copy of other.

Calls C++ function: [constructor] void QJSValue::QJSValue(const QJSValue& other).

C++ documentation:

Constructs a new QJSValue that is a copy of other.

Note that if other is an object (i.e., isObject() would return true), then only a reference to the underlying object is copied into the new script value (i.e., the object itself is not copied).

pub unsafe fn property_q_string(
    &self,
    name: impl CastInto<Ref<QString>>
) -> CppBox<QJSValue>
[src]

Returns the value of this QJSValue's property with the given name. If no such property exists, an undefined QJSValue is returned.

Calls C++ function: QJSValue QJSValue::property(const QString& name) const.

C++ documentation:

Returns the value of this QJSValue's property with the given name. If no such property exists, an undefined QJSValue is returned.

If the property is implemented using a getter function (i.e. has the PropertyGetter flag set), calling property() has side-effects on the script engine, since the getter function will be called (possibly resulting in an uncaught script exception). If an exception occurred, property() returns the value that was thrown (typically an Error object).

To access array elements, use the setProperty(quint32 arrayIndex, const QJSValue &value) overload instead.

See also setProperty(), hasProperty(), and QJSValueIterator.

pub unsafe fn property_u32(&self, array_index: u32) -> CppBox<QJSValue>[src]

This is an overloaded function.

Calls C++ function: QJSValue QJSValue::property(quint32 arrayIndex) const.

C++ documentation:

This is an overloaded function.

Returns the property at the given arrayIndex.

It is possible to access elements in an array in two ways. The first is to use the array index as the property name:

qDebug() << jsValueArray.property(QLatin1String("4")).toString();

The second is to use the overload that takes an index:

qDebug() << jsValueArray.property(4).toString();

Both of these approaches achieve the same result, except that the latter:

  • Is easier to use (can use an integer directly)
  • Is faster (no conversion to integer)

If this QJSValue is not an Array object, this function behaves as if property() was called with the string representation of arrayIndex.

pub unsafe fn prototype(&self) -> CppBox<QJSValue>[src]

If this QJSValue is an object, returns the internal prototype (__proto__ property) of this object; otherwise returns an undefined QJSValue.

Calls C++ function: QJSValue QJSValue::prototype() const.

C++ documentation:

If this QJSValue is an object, returns the internal prototype (proto property) of this object; otherwise returns an undefined QJSValue.

See also setPrototype() and isObject().

pub unsafe fn set_property_q_string_q_j_s_value(
    &self,
    name: impl CastInto<Ref<QString>>,
    value: impl CastInto<Ref<QJSValue>>
)
[src]

Sets the value of this QJSValue's property with the given name to the given value.

Calls C++ function: void QJSValue::setProperty(const QString& name, const QJSValue& value).

C++ documentation:

Sets the value of this QJSValue's property with the given name to the given value.

If this QJSValue is not an object, this function does nothing.

If this QJSValue does not already have a property with name name, a new property is created.

To modify array elements, use the setProperty(quint32 arrayIndex, const QJSValue &value) overload instead.

See also property() and deleteProperty().

pub unsafe fn set_property_u32_q_j_s_value(
    &self,
    array_index: u32,
    value: impl CastInto<Ref<QJSValue>>
)
[src]

This is an overloaded function.

Calls C++ function: void QJSValue::setProperty(quint32 arrayIndex, const QJSValue& value).

C++ documentation:

This is an overloaded function.

Sets the property at the given arrayIndex to the given value.

It is possible to modify elements in an array in two ways. The first is to use the array index as the property name:

jsValueArray.setProperty(QLatin1String("4"), value);

The second is to use the overload that takes an index:

jsValueArray.setProperty(4, value);

Both of these approaches achieve the same result, except that the latter:

  • Is easier to use (can use an integer directly)
  • Is faster (no conversion to integer)

If this QJSValue is not an Array object, this function behaves as if setProperty() was called with the string representation of arrayIndex.

See also property(quint32 arrayIndex) and Working With Arrays.

pub unsafe fn set_prototype(&self, prototype: impl CastInto<Ref<QJSValue>>)[src]

If this QJSValue is an object, sets the internal prototype (__proto__ property) of this object to be prototype; if the QJSValue is null, it sets the prototype to null; otherwise does nothing.

Calls C++ function: void QJSValue::setPrototype(const QJSValue& prototype).

C++ documentation:

If this QJSValue is an object, sets the internal prototype (proto property) of this object to be prototype; if the QJSValue is null, it sets the prototype to null; otherwise does nothing.

The internal prototype should not be confused with the public property with name "prototype"; the public prototype is usually only set on functions that act as constructors.

See also prototype() and isObject().

pub unsafe fn strictly_equals(
    &self,
    other: impl CastInto<Ref<QJSValue>>
) -> bool
[src]

Returns true if this QJSValue is equal to other using strict comparison (no conversion), otherwise returns false. The comparison follows the behavior described in ECMA-262 section 11.9.6, "The Strict Equality Comparison Algorithm".

Calls C++ function: bool QJSValue::strictlyEquals(const QJSValue& other) const.

C++ documentation:

Returns true if this QJSValue is equal to other using strict comparison (no conversion), otherwise returns false. The comparison follows the behavior described in ECMA-262 section 11.9.6, "The Strict Equality Comparison Algorithm".

If the type of this QJSValue is different from the type of the other value, this function returns false. If the types are equal, the result depends on the type, as shown in the following table:

TypeResult
Undefinedtrue
Nulltrue
Booleantrue if both values are true, false otherwise
Numberfalse if either value is NaN (Not-a-Number); true if values are equal, false otherwise
Stringtrue if both values are exactly the same sequence of characters, false otherwise
Objecttrue if both values refer to the same object, false otherwise

See also equals().

pub unsafe fn to_bool(&self) -> bool[src]

Returns the boolean value of this QJSValue, using the conversion rules described in ECMA-262 section 9.2, "ToBoolean".

Calls C++ function: bool QJSValue::toBool() const.

C++ documentation:

Returns the boolean value of this QJSValue, using the conversion rules described in ECMA-262 section 9.2, "ToBoolean".

Note that if this QJSValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also isBool().

pub unsafe fn to_date_time(&self) -> CppBox<QDateTime>[src]

Returns a QDateTime representation of this value, in local time. If this QJSValue is not a date, or the value of the date is NaN (Not-a-Number), an invalid QDateTime is returned.

Calls C++ function: QDateTime QJSValue::toDateTime() const.

C++ documentation:

Returns a QDateTime representation of this value, in local time. If this QJSValue is not a date, or the value of the date is NaN (Not-a-Number), an invalid QDateTime is returned.

See also isDate().

pub unsafe fn to_int(&self) -> i32[src]

Returns the signed 32-bit integer value of this QJSValue, using the conversion rules described in ECMA-262 section 9.5, "ToInt32".

Calls C++ function: qint32 QJSValue::toInt() const.

C++ documentation:

Returns the signed 32-bit integer value of this QJSValue, using the conversion rules described in ECMA-262 section 9.5, "ToInt32".

Note that if this QJSValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also toNumber() and toUInt().

pub unsafe fn to_number(&self) -> c_double[src]

Returns the number value of this QJSValue, as defined in ECMA-262 section 9.3, "ToNumber".

Calls C++ function: double QJSValue::toNumber() const.

C++ documentation:

Returns the number value of this QJSValue, as defined in ECMA-262 section 9.3, "ToNumber".

Note that if this QJSValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also isNumber(), toInt(), and toUInt().

pub unsafe fn to_q_meta_object(&self) -> Ptr<QMetaObject>[src]

* If this QJSValue is a QMetaObject, returns the QMetaObject pointer * that the QJSValue represents; otherwise, returns nullptr. * *

Calls C++ function: const QMetaObject* QJSValue::toQMetaObject() const.

C++ documentation:

* If this QJSValue is a QMetaObject, returns the QMetaObject pointer * that the QJSValue represents; otherwise, returns nullptr. * *

This function was introduced in Qt 5.8.

See also isQMetaObject().

pub unsafe fn to_q_object(&self) -> QPtr<QObject>[src]

If this QJSValue is a QObject, returns the QObject pointer that the QJSValue represents; otherwise, returns nullptr.

Calls C++ function: QObject* QJSValue::toQObject() const.

C++ documentation:

If this QJSValue is a QObject, returns the QObject pointer that the QJSValue represents; otherwise, returns nullptr.

If the QObject that this QJSValue wraps has been deleted, this function returns nullptr (i.e. it is possible for toQObject() to return nullptr even when isQObject() returns true).

See also isQObject().

pub unsafe fn to_string(&self) -> CppBox<QString>[src]

Returns the string value of this QJSValue, as defined in ECMA-262 section 9.8, "ToString".

Calls C++ function: QString QJSValue::toString() const.

C++ documentation:

Returns the string value of this QJSValue, as defined in ECMA-262 section 9.8, "ToString".

Note that if this QJSValue is an object, calling this function has side effects on the script engine, since the engine will call the object's toString() function (and possibly valueOf()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also isString().

pub unsafe fn to_u_int(&self) -> u32[src]

Returns the unsigned 32-bit integer value of this QJSValue, using the conversion rules described in ECMA-262 section 9.6, "ToUint32".

Calls C++ function: quint32 QJSValue::toUInt() const.

C++ documentation:

Returns the unsigned 32-bit integer value of this QJSValue, using the conversion rules described in ECMA-262 section 9.6, "ToUint32".

Note that if this QJSValue is an object, calling this function has side effects on the script engine, since the engine will call the object's valueOf() function (and possibly toString()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).

See also toNumber() and toInt().

pub unsafe fn to_variant(&self) -> CppBox<QVariant>[src]

Returns the QVariant value of this QJSValue, if it can be converted to a QVariant; otherwise returns an invalid QVariant. The conversion is performed according to the following table:

Calls C++ function: QVariant QJSValue::toVariant() const.

C++ documentation:

Returns the QVariant value of this QJSValue, if it can be converted to a QVariant; otherwise returns an invalid QVariant. The conversion is performed according to the following table:

Input TypeResult
UndefinedAn invalid QVariant.
NullA QVariant containing a null pointer (QMetaType::Nullptr).
BooleanA QVariant containing the value of the boolean.
NumberA QVariant containing the value of the number.
StringA QVariant containing the value of the string.
QVariant ObjectThe result is the QVariant value of the object (no conversion).
QObject ObjectA QVariant containing a pointer to the QObject.
Date ObjectA QVariant containing the date value (toDateTime()).
RegExp ObjectA QVariant containing the regular expression value.
Array ObjectThe array is converted to a QVariantList. Each element is converted to a QVariant, recursively; cyclic references are not followed.
ObjectThe object is converted to a QVariantMap. Each property is converted to a QVariant, recursively; cyclic references are not followed.

See also isVariant().

Trait Implementations

impl CppDeletable for QJSValue[src]

unsafe fn delete(&self)[src]

Destroys this QJSValue.

Calls C++ function: [destructor] void QJSValue::~QJSValue().

C++ documentation:

Destroys this QJSValue.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.