| Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |
The QScriptValue class acts as a container for the Qt Script data types. More...
#include <QScriptValue>
This class was introduced in Qt 4.3.
The QScriptValue class acts as a container for the Qt Script data types.
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 defines two types: Variant (a QVariant), and QObject (a pointer to a QObject (or subclass)). Custom types are supported by means of the Qt meta type system; see qScriptRegisterMetaType().
To obtain a QScriptValue, you use one of the scriptValue() or scriptValueFromT() methods in QScriptEngine (e.g. QScriptEngine::scriptValue(123)).
The methods named isT() (e.g. isBoolean(), isUndefined()) can be used to test if a value is of a certain type. The methods named toT() (e.g. toBoolean(), toString()) can be used to convert a 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 setProperty() to set a property of an object, and call property() to retrieve the value of a property.
Object values have an internal prototype property, which can be accessed with prototype() and setPrototype(). Properties added to a prototype are shared by all objects having that prototype. For more information, see the QtScript documentation.
Function objects (objects for which isFunction() returns true) can be invoked by calling call().
See also QScriptEngine.
This enum describes the attributes of a property.
| Constant | Value | Description |
|---|---|---|
| QScriptValue::ReadOnly | 0x00000001 | The property is read-only. Attempts by Qt Script code to write to the property will be ignored. |
| QScriptValue::Undeletable | 0x00000002 | Attempts by Qt Script code to delete the property will be ignored. |
| QScriptValue::SkipInEnumeration | 0x00000004 | The property is not to be enumerated by a for-in enumeration. |
| QScriptValue::PropertyGetter | 0x00000400 | The property is defined by a function which will be called to get the property value. |
| QScriptValue::PropertySetter | 0x00000800 | The property is defined by a function which will be called to set the property value. |
| QScriptValue::UserRange | 0xffff0000 | Flags in this range are not used by Qt Script, and can be used for custom purposes. |
The PropertyFlags type is a typedef for QFlags<PropertyFlag>. It stores an OR combination of PropertyFlag values.
This enum specifies how to look up a property of an object.
| Constant | Value | Description |
|---|---|---|
| QScriptValue::ResolveLocal | 0x00 | Only check the object's own properties. This is the default. |
| QScriptValue::ResolvePrototype | 0x01 | Check the object's own properties first, then search the prototype chain. |
| QScriptValue::ResolveScope | 0x02 | Check the object's own properties first, then search the scope chain. |
| QScriptValue::ResolveFull | ResolvePrototype | ResolveScope | Check the object's own properties first, then search the prototype chain, and finally search the scope chain. |
The ResolveFlags type is a typedef for QFlags<ResolveFlag>. It stores an OR combination of ResolveFlag values.
This enum is used to provide toPrimitive() with the desired type of the return value.
| Constant | Value | Description |
|---|---|---|
| QScriptValue::NoTypeHint | 0 | No hint. |
| QScriptValue::NumberTypeHint | 1 | A number value is desired. |
| QScriptValue::StringTypeHint | 2 | A string value is desired. |
Constructs an invalid QScriptValue.
Constructs a new QScriptValue with a boolean value, val.
Constructs a new QScriptValue with an integer value, val.
Constructs a new QScriptValue with an unsigned integer value, val.
Constructs a new QScriptValue with a qlonglong value, val.
Constructs a new QScriptValue with a qulonglong value, val.
Constructs a new QScriptValue with a qsreal value, val.
Constructs a new QScriptValue with a string value, val.
Constructs a new QScriptValue with a string value, val.
Calls this QScriptValue as a function, using thisObject 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 QScriptValue is not a function, call() does nothing and returns an invalid QScriptValue.
Note that if thisObject is not an object, the global object (see QScriptEngine::globalObject()) will be used as the `this' object.
See also isFunction().
Decreases the reference count of this QScriptValue by one.
Use this function in combination with ref() to ensure that a QScriptValue is not garbage collected.
See also ref().
Returns the QScriptEngine that created this QScriptValue, or 0 if this QScriptValue is invalid.
Returns true if this 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".
Returns true if this QScriptValue is an instance of ctorValue; otherwise returns false.
A QScriptValue A is considered to be an instance of QScriptValue B if B is in the prototype chain of A.
Returns true if this QScriptValue is an object of the Array class; otherwise returns false.
See also QScriptEngine::newArray().
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false.
See also toBoolean().
Returns true if this QScriptValue is an object of the Date class; otherwise returns false.
See also QScriptEngine::newDate().
Returns true if this QScriptValue is an object of the Error class; otherwise returns false.
See also QScriptContext::throwError().
Returns true if this QScriptValue is a function; otherwise returns false.
See also call().
Returns true if this QScriptValue is of the primitive type Null; otherwise returns false.
See also QScriptEngine::nullScriptValue().
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false.
See also toNumber().
Returns true if this QScriptValue is of the Object type; otherwise returns false.
Note that function values, variant values and QObject values are objects, so this function will return true for such values.
See also toObject(), toPrimitive(), and QScriptEngine::newObject().
Returns true if this QScriptValue is a QObject; otherwise returns false.
See also toQObject() and QScriptEngine::newQObject().
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false.
See also QScriptEngine::newRegExp().
Returns true if this QScriptValue is of the primitive type String; otherwise returns false.
See also toString().
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false.
See also QScriptEngine::undefinedScriptValue().
Returns true if this QScriptValue is valid; otherwise returns false.
Returns true if this QScriptValue is a variant value; otherwise returns false.
See also toVariant() and QScriptEngine::newVariant().
Returns true if this 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".
Returns the value of this QScriptValue's property with the given name, using the given mode to resolve the property.
If no such property exists, an invalid QScriptValue is returned.
See also setProperty().
This is an overloaded member function, provided for convenience.
Returns the property at the given arrayIndex.
This function is provided for convenience and performance when working with array objects.
If this QScriptValue is an object, returns the internal prototype (__proto__ property) of this object; otherwise returns an invalid QScriptValue.
See also setPrototype() and isObject().
Increases the reference count of this QScriptValue by one.
This function provides a way to ensure that the value is not garbage collected, even if the value is not reachable from the script environment (e.g. by tracing properties of the Global Object or local variables).
Call this function if you are storing the QScriptValue as a member in your class, or otherwise need to make sure that this particular value is not garbage collected over a period of time.
You should call deref() when the value is no longer needed.
See also deref().
Sets the value of this QScriptValue's property with the given name to the given value.
If this QScriptValue is not an object, this function does nothing.
If this 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.
See also property().
This is an overloaded member function, provided for convenience.
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 QScriptValue is an object, sets the internal prototype (__proto__ property) of this object to be prototype; otherwise does nothing.
See also prototype() and isObject().
Sets the variant value of this QScriptValue to be the given value. If this QScriptValue is not a variant, this function does nothing.
See also isVariant() and toVariant().
Returns true if this 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".
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.2, "ToBoolean".
See also isBoolean().
Returns the QDateTime representation of this value. If this QScriptValue is not a date, or the value of the date is NaN (Not-a-Number), an invalid QDateTime is returned.
See also isDate().
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.5, "ToInt32".
See also toNumber() and toUInt32().
Returns the integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.4, "ToInteger".
See also toNumber().
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToString".
See also isNumber(), toInteger(), toInt32(), toUInt32(), and toUInt16().
Returns the object value of this QScriptValue, as defined in ECMA-262 section 9.9, "ToObject".
See also isObject().
Returns the primitive value of this QScriptValue, as defined in ECMA-262 section 9.1, "ToPrimitive".
If this QScriptValue is an object, the given hint can be used to indicate the desired primitive type.
Returns the QObject value of this QScriptValue.
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; otherwise, returns 0.
See also isQObject().
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
See also isString().
Returns the unsigned 16-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.7, "ToUint16".
See also toNumber().
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described in ECMA-262 section 9.6, "ToUint32".
See also toNumber() and toInt32().
Returns the variant value of this QScriptValue.
See also isVariant().
Returns the given value converted to the template type T.
See also qScriptRegisterMetaType() and QScriptEngine::toScriptValue().
| Copyright © 2007 Trolltech | Trademarks | Qt 4.3.0-snapshot-20070202 |