The PySide.QtScript.QScriptValue class acts as a container for the Qt Script data types.
PySide.QtScript.QScriptValue supports the types defined in the ECMA-262 standard: The primitive types, which are Undefined, Null, Boolean, Number, and String; and the Object type. Additionally, Qt Script has built-in support for PySide.QtCore.QVariant , PySide.QtCore.QObject and PySide.QtCore.QMetaObject .
For the object-based types (including Date and RegExp), use the newT() functions in PySide.QtScript.QScriptEngine (e.g. QScriptEngine.newObject() ) to create a PySide.QtScript.QScriptValue of the desired type. For the primitive types, use one of the PySide.QtScript.QScriptValue constructor overloads.
The methods named isT() (e.g. PySide.QtScript.QScriptValue.isBool() , PySide.QtScript.QScriptValue.isUndefined() ) can be used to test if a value is of a certain type. The methods named toT() (e.g. PySide.QtScript.QScriptValue.toBool() , PySide.QtScript.QScriptValue.toString() ) can be used to convert a PySide.QtScript.QScriptValue to another type. You can also use the generic qscriptvalue_cast() function.
Object values have zero or more properties which are themselves QScriptValues. Use PySide.QtScript.QScriptValue.setProperty() to set a property of an object, and call PySide.QtScript.QScriptValue.property() to retrieve the value of a property.
myEngine = QScriptEngine() myObject = myEngine.newObject() myOtherObject = myEngine.newObject() myObject.setProperty("myChild", myOtherObject) myObject.setProperty("name", "John Doe")Each property can have a set of attributes; these are specified as the third (optional) argument to PySide.QtScript.QScriptValue.setProperty() . The attributes of a property can be queried by calling the PySide.QtScript.QScriptValue.propertyFlags() function. The following code snippet creates a property that cannot be modified by script code:
val = QScriptValue(myEngine, 123) myObject.setProperty("myReadOnlyProperty", val, QScriptValue.ReadOnly)If you want to iterate over the properties of a script object, use the PySide.QtScript.QScriptValueIterator class.
Object values have an internal prototype property, which can be accessed with PySide.QtScript.QScriptValue.prototype() and PySide.QtScript.QScriptValue.setPrototype() . Properties added to a prototype are shared by all objects having that prototype; this is referred to as prototype-based inheritance. In practice, it means that (by default) the PySide.QtScript.QScriptValue.property() function will automatically attempt to look up look the property in the PySide.QtScript.QScriptValue.prototype() (and in the prototype of the PySide.QtScript.QScriptValue.prototype() , and so on), if the object itself does not have the requested property. Note that this prototype-based lookup is not performed by PySide.QtScript.QScriptValue.setProperty() ; PySide.QtScript.QScriptValue.setProperty() will always create the property in the script object itself. For more information, see the QtScript documentation.
Function objects (objects for which PySide.QtScript.QScriptValue.isFunction() returns true) can be invoked by calling PySide.QtScript.QScriptValue.call() . Constructor functions can be used to construct new objects by calling PySide.QtScript.QScriptValue.construct() .
Use PySide.QtScript.QScriptValue.equals() , PySide.QtScript.QScriptValue.strictlyEquals() and PySide.QtScript.QScriptValue.lessThan() to compare a PySide.QtScript.QScriptValue to another.
Object values can have custom data associated with them; see the PySide.QtScript.QScriptValue.setData() and PySide.QtScript.QScriptValue.data() functions. By default, this data is not accessible to scripts; it can be used to store any data you want to associate with the script object. Typically this is used by custom class objects (see PySide.QtScript.QScriptClass ) to store a C++ type that contains the “native” object data.
Note that a PySide.QtScript.QScriptValue for which PySide.QtScript.QScriptValue.isObject() is true only carries a reference to an actual object; copying the PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValueIterator in C++.
Parameters: |
---|
Constructs an invalid PySide.QtScript.QScriptValue .
Constructs a new PySide.QtScript.QScriptValue with the special value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with the boolean value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with the string value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with the string value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with the integer value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with the unsigned integer value and registers it with the script engine .
Constructs a new PySide.QtScript.QScriptValue with a special value .
Constructs a new PySide.QtScript.QScriptValue with a boolean value .
Constructs a new PySide.QtScript.QScriptValue that is a copy of other .
Note that if other is an object (i.e., PySide.QtScript.QScriptValue.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).
Constructs a new PySide.QtScript.QScriptValue with a string value .
Constructs a new PySide.QtScript.QScriptValue with a string value .
Constructs a new PySide.QtScript.QScriptValue with a number value .
Constructs a new PySide.QtScript.QScriptValue with a number value .
This enum specifies how to look up a property of an object.
Constant | Description |
---|---|
QScriptValue.ResolveLocal | Only check the object’s own properties. |
QScriptValue.ResolvePrototype | Check the object’s own properties first, then search the prototype chain. This is the default. |
Check the object’s own properties first, then search the scope chain.
Check the object’s own properties first, then search the prototype chain, and finally search the scope chain.
This enum describes the attributes of a property.
Constant | Description |
---|---|
QScriptValue.ReadOnly | The property is read-only. Attempts by Qt Script code to write to the property will be ignored. |
QScriptValue.Undeletable | Attempts by Qt Script code to delete the property will be ignored. |
QScriptValue.SkipInEnumeration | The property is not to be enumerated by a for-in enumeration. |
QScriptValue.PropertyGetter | The property is defined by a function which will be called to get the property value. |
QScriptValue.PropertySetter | The property is defined by a function which will be called to set the property value. |
This flag is used to indicate that an existing property is a PySide.QtCore.QObject member (a property or method).
Constant | Description |
---|---|
QScriptValue.KeepExistingFlags | This value is used to indicate to PySide.QtScript.QScriptValue.setProperty() that the property’s flags should be left unchanged. If the property doesn’t exist, the default flags (0) will be used. |
Flags in this range are not used by Qt Script, and can be used for custom purposes.
This enum is used to specify a single-valued type.
Constant | Description |
---|---|
QScriptValue.UndefinedValue | An undefined value. |
QScriptValue.NullValue | A null value. |
Return type: | PyObject |
---|
Return type: | PyObject |
---|
Parameters: |
|
---|---|
Return type: |
Calls this PySide.QtScript.QScriptValue as a function, using thisObject as the this’ object in the function call, and passing ``arguments` as arguments to the function. Returns the value returned from the function.
If this PySide.QtScript.QScriptValue is not a function, PySide.QtScript.QScriptValue.call() does nothing and returns an invalid PySide.QtScript.QScriptValue .
arguments can be an arguments object, an array, null or undefined; any other type will cause a TypeError to be thrown.
Note that if thisObject is not an object, the global object (see QScriptEngine.globalObject() ) will be used as the `this’ object.
One common usage of this function is to forward native function calls to another function:
def myNativeFunction(context, engine):
otherFunction = ...
return otherFunction.call(context.thisObject(), context.argumentsObject())
Parameters: |
|
---|---|
Return type: |
Parameters: | args – |
---|---|
Return type: | PySide.QtScript.QScriptValue |
Parameters: | arguments – PySide.QtScript.QScriptValue |
---|---|
Return type: | PySide.QtScript.QScriptValue |
Creates a new Object and calls this PySide.QtScript.QScriptValue as a constructor, using the created object as the this’ object and passing ``arguments` 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 PySide.QtScript.QScriptValue is not a function, PySide.QtScript.QScriptValue.construct() does nothing and returns an invalid PySide.QtScript.QScriptValue .
arguments can be an arguments object, an array, null or undefined. Any other type will cause a TypeError to be thrown.
Return type: | PySide.QtScript.QScriptValue |
---|
Returns the internal data of this PySide.QtScript.QScriptValue object. QtScript uses this property to store the primitive value of Date, String, Number and Boolean objects. For other types of object, custom data may be stored using PySide.QtScript.QScriptValue.setData() .
Return type: | PySide.QtScript.QScriptEngine |
---|
Returns the PySide.QtScript.QScriptEngine that created this PySide.QtScript.QScriptValue , or 0 if this PySide.QtScript.QScriptValue is invalid or the value is not associated with a particular engine.
Parameters: | other – PySide.QtScript.QScriptValue |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.strictlyEquals() .
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Parameters: | other – PySide.QtScript.QScriptValue |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this PySide.QtScript.QScriptValue is an instance of other ; otherwise returns false.
This PySide.QtScript.QScriptValue is considered to be an instance of other if other is a function and the value of the prototype property of other is in the prototype chain of this PySide.QtScript.QScriptValue .
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is an object of the Array class; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the primitive type Boolean; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Use PySide.QtScript.QScriptValue.isBool() instead.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is an object of the Date class; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is an object of the Error class; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is a function; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the primitive type Null; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the primitive type Number; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the Object type; otherwise returns false.
Note that function values, variant values, and PySide.QtCore.QObject values are objects, so this function returns true for such values.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is a PySide.QtCore.QMetaObject ; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is a PySide.QtCore.QObject ; otherwise returns false.
Note: This function returns true even if the PySide.QtCore.QObject that this PySide.QtScript.QScriptValue wraps has been deleted.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is an object of the RegExp class; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the primitive type String; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is of the primitive type Undefined; otherwise returns false.
See also
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is valid; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if this PySide.QtScript.QScriptValue is a variant value; otherwise returns false.
Parameters: | other – PySide.QtScript.QScriptValue |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this PySide.QtScript.QScriptValue is less than other , otherwise returns false. The comparison follows the behavior described in ECMA-262 section 11.8.5, “The Abstract Relational Comparison Algorithm”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.qint64 |
---|
Returns the ID of this object, or -1 if this PySide.QtScript.QScriptValue is not an object.
See also
Parameters: |
|
---|---|
Return type: |
This is an overloaded function.
Returns the property at the given arrayIndex , using the given mode to resolve the property.
This function is provided for convenience and performance when working with array objects.
If this PySide.QtScript.QScriptValue is not an Array object, this function behaves as if PySide.QtScript.QScriptValue.property() was called with the string representation of arrayIndex .
Parameters: |
|
---|---|
Return type: |
Returns the value of this PySide.QtScript.QScriptValue ‘s property with the given name , using the given mode to resolve the property.
If no such property exists, an invalid PySide.QtScript.QScriptValue is returned.
If the property is implemented using a getter function (i.e. has the PropertyGetter flag set), calling PySide.QtScript.QScriptValue.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, PySide.QtScript.QScriptValue.property() returns the value that was thrown (typically an Error object).
Parameters: |
|
---|---|
Return type: |
Returns the value of this PySide.QtScript.QScriptValue ‘s property with the given name , using the given mode to resolve the property.
This overload of PySide.QtScript.QScriptValue.property() is useful when you need to look up the same property repeatedly, since the lookup can be performed faster when the name is represented as an interned string.
Parameters: |
|
---|---|
Return type: | PySide.QtScript.QScriptValue.PropertyFlags |
Returns the flags of the property with the given name , using the given mode to resolve the property.
Parameters: |
|
---|---|
Return type: | PySide.QtScript.QScriptValue.PropertyFlags |
Returns the flags of the property with the given name , using the given mode to resolve the property.
Return type: | PySide.QtScript.QScriptValue |
---|
If this PySide.QtScript.QScriptValue is an object, returns the internal prototype (__proto__ property) of this object; otherwise returns an invalid PySide.QtScript.QScriptValue .
Return type: | PySide.QtScript.QScriptValue |
---|
Return type: | PySide.QtScript.QScriptClass |
---|
Returns the custom script class that this script object is an instance of, or 0 if the object is not of a custom class.
Parameters: | data – PySide.QtScript.QScriptValue |
---|
Sets the internal data of this PySide.QtScript.QScriptValue object. You can use this function to set object-specific data that won’t be directly accessible to scripts, but may be retrieved in C++ using the PySide.QtScript.QScriptValue.data() function.
Parameters: |
|
---|
Sets the value of this PySide.QtScript.QScriptValue ‘s property with the given name to the given value .
If this PySide.QtScript.QScriptValue is not an object, this function does nothing.
If this PySide.QtScript.QScriptValue does not already have a property with name name , a new property is created; the given flags then specify how this property may be accessed by script code.
If value is invalid, the property is removed.
If the property is implemented using a setter function (i.e. has the PropertySetter flag set), calling PySide.QtScript.QScriptValue.setProperty() has side-effects on the script engine, since the setter function will be called with the given value as argument (possibly resulting in an uncaught script exception).
Note that you cannot specify custom getter or setter functions for built-in properties, such as the length property of Array objects or meta properties of PySide.QtCore.QObject objects.
Parameters: |
|
---|
This is an overloaded function.
Sets the property at the given arrayIndex to the given value .
This function is provided for convenience and performance when working with array objects.
If this PySide.QtScript.QScriptValue is not an Array object, this function behaves as if PySide.QtScript.QScriptValue.setProperty() was called with the string representation of arrayIndex .
Parameters: |
|
---|
Sets the value of this PySide.QtScript.QScriptValue ‘s property with the given name to the given value . The given flags specify how this property may be accessed by script code.
This overload of PySide.QtScript.QScriptValue.setProperty() is useful when you need to set the same property repeatedly, since the operation can be performed faster when the name is represented as an interned string.
See also
Parameters: | prototype – PySide.QtScript.QScriptValue |
---|
If this PySide.QtScript.QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to be prototype ; 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.
Parameters: | scope – PySide.QtScript.QScriptValue |
---|
Parameters: | scriptClass – PySide.QtScript.QScriptClass |
---|
Sets the custom script class of this script object to scriptClass . This can be used to “promote” a plain script object (e.g. created by the “new” operator in a script, or by QScriptEngine.newObject() in C++) to an object of a custom type.
If scriptClass is 0, the object will be demoted to a plain script object.
Parameters: | other – PySide.QtScript.QScriptValue |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue 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:
Type | Result |
Undefined | true |
Null | true |
Boolean | true if both values are true, false otherwise |
Number | false if either value is NaN (Not-a-Number); true if values are equal, false otherwise |
String | true if both values are exactly the same sequence of characters, false otherwise |
Object | true if both values refer to the same object, false otherwise |
Return type: | PySide.QtCore.bool |
---|
Returns the boolean value of this PySide.QtScript.QScriptValue , using the conversion rules described in ECMA-262 section 9.2, “ToBoolean”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.bool |
---|
Use PySide.QtScript.QScriptValue.toBool() instead.
Return type: | PySide.QtCore.QDateTime |
---|
Returns a PySide.QtCore.QDateTime representation of this value, in local time. If this PySide.QtScript.QScriptValue is not a date, or the value of the date is NaN (Not-a-Number), an invalid PySide.QtCore.QDateTime is returned.
Return type: | PySide.QtCore.qint32 |
---|
Returns the signed 32-bit integer value of this PySide.QtScript.QScriptValue , using the conversion rules described in ECMA-262 section 9.5, “ToInt32”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.double |
---|
Returns the integer value of this PySide.QtScript.QScriptValue , using the conversion rules described in ECMA-262 section 9.4, “ToInteger”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.double |
---|
Returns the number value of this PySide.QtScript.QScriptValue , as defined in ECMA-262 section 9.3, “ToNumber”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtScript.QScriptValue |
---|
This function is obsolete; use QScriptEngine.toObject() instead.
Return type: | PySide.QtCore.QMetaObject |
---|
If this PySide.QtScript.QScriptValue is a PySide.QtCore.QMetaObject , returns the PySide.QtCore.QMetaObject pointer that the PySide.QtScript.QScriptValue represents; otherwise, returns 0.
Return type: | PySide.QtCore.QObject |
---|
If this PySide.QtScript.QScriptValue is a PySide.QtCore.QObject , returns the PySide.QtCore.QObject pointer that the PySide.QtScript.QScriptValue represents; otherwise, returns 0.
If the PySide.QtCore.QObject that this PySide.QtScript.QScriptValue wraps has been deleted, this function returns 0 (i.e. it is possible for PySide.QtScript.QScriptValue.toQObject() to return 0 even when PySide.QtScript.QScriptValue.isQObject() returns true).
Return type: | PySide.QtCore.QRegExp |
---|
Returns the PySide.QtCore.QRegExp representation of this value. If this PySide.QtScript.QScriptValue is not a regular expression, an empty PySide.QtCore.QRegExp is returned.
Return type: | unicode |
---|
Returns the string value of this PySide.QtScript.QScriptValue , as defined in ECMA-262 section 9.8, “ToString”.
Note that if this PySide.QtScript.QScriptValue is an object, calling this function has side effects on the script engine, since the engine will call the object’s PySide.QtScript.QScriptValue.toString() function (and possibly valueOf()) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.quint16 |
---|
Returns the unsigned 16-bit integer value of this PySide.QtScript.QScriptValue , using the conversion rules described in ECMA-262 section 9.7, “ToUint16”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | PySide.QtCore.quint32 |
---|
Returns the unsigned 32-bit integer value of this PySide.QtScript.QScriptValue , using the conversion rules described in ECMA-262 section 9.6, “ToUint32”.
Note that if this PySide.QtScript.QScriptValue 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 PySide.QtScript.QScriptValue.toString() ) in an attempt to convert the object to a primitive value (possibly resulting in an uncaught script exception).
Return type: | object |
---|
Returns the PySide.QtCore.QVariant value of this PySide.QtScript.QScriptValue , if it can be converted to a PySide.QtCore.QVariant ; otherwise returns an invalid PySide.QtCore.QVariant . The conversion is performed according to the following table:
Input Type | Result |
Undefined | An invalid PySide.QtCore.QVariant . |
Null | An invalid PySide.QtCore.QVariant . |
Boolean | A PySide.QtCore.QVariant containing the value of the boolean. |
Number | A PySide.QtCore.QVariant containing the value of the number. |
String | A PySide.QtCore.QVariant containing the value of the string. |
PySide.QtCore.QVariant Object | The result is the PySide.QtCore.QVariant value of the object (no conversion). |
PySide.QtCore.QObject Object | A PySide.QtCore.QVariant containing a pointer to the PySide.QtCore.QObject . |
Date Object | A PySide.QtCore.QVariant containing the date value ( PySide.QtScript.QScriptValue.toDateTime() ). |
RegExp Object | A PySide.QtCore.QVariant containing the regular expression value ( PySide.QtScript.QScriptValue.toRegExp() ). |
Array Object | The array is converted to a QVariantList . Each element is converted to a PySide.QtCore.QVariant , recursively; cyclic references are not followed. |
Object | The object is converted to a PySide.QtCore.QVariantMap . Each property is converted to a PySide.QtCore.QVariant , recursively; cyclic references are not followed. |