PySide6.QtQml.QJSManagedValue¶
- class QJSManagedValue¶
- QJSManagedValuerepresents a value on the JavaScript heap belonging to a- QJSEngine.- Details- The - QJSManagedValueclass allows interaction with JavaScript values in most ways you can interact with them from JavaScript itself. You can get and set properties and prototypes, and you can access arrays. Additionally, you can transform the value into the Qt counterparts of JavaScript objects. For example, a Url object may be transformed into a QUrl.- A - QJSManagedValueis always bound to a particular- QJSEngine. You cannot use it independently. This means that you cannot have a- QJSManagedValuefrom one engine be a property or a proptotype of a- QJSManagedValuefrom a different engine.- In contrast to - QJSValue, almost all values held by- QJSManagedValuelive on the JavaScript heap. There is no inline or unmanaged storage. Therefore, you can get the prototype of a primitive value, and you can get the- lengthproperty of a string.- Only default-constructed or moved-from QJSManagedValues do not hold a value on the JavaScript heap. They represent - undefined, which doesn’t have any properties or prototypes.- Also in contrast to - QJSValue,- QJSManagedValuedoes not catch any JavaScript exceptions. If an operation on a- QJSManagedValuecauses an error, it will generally return an- undefinedvalue and- hasError()will return- trueafterwards. You can then catch the exception using- catchError(), or pass it up the stack, at your own discretion.- Note - As the reference to the value on the JavaScript heap has to be freed on destruction, you cannot move a - QJSManagedValueto a different thread. The destruction would take place in the new thread, which would create a race condition with the garbage collector on the original thread. This also means that you cannot hold a- QJSManagedValuebeyond the lifespan of its engine.- The recommended way of working with a - QJSManagedValueis creating it on the stack, possibly by moving a- QJSValueand adding an engine, then performing the necessary operations on it, and finally moving it back into a- QJSValuefor storage. Moving between- QJSManagedValueand- QJSValueis fast.- Synopsis¶- Methods¶- def - __init__()
- def - call()
- def - deleteProperty()
- def - engine()
- def - equals()
- def - hasOwnProperty()
- def - hasProperty()
- def - isArray()
- def - isBoolean()
- def - isDate()
- def - isError()
- def - isFunction()
- def - isInteger()
- def - isJsMetaType()
- def - isNull()
- def - isNumber()
- def - isObject()
- def - isQMetaObject()
- def - isQObject()
- def - isString()
- def - isSymbol()
- def - isUndefined()
- def - isUrl()
- def - isVariant()
- def - jsMetaMembers()
- def - jsMetaType()
- def - property()
- def - prototype()
- def - setProperty()
- def - setPrototype()
- def - strictlyEquals()
- def - toBoolean()
- def - toDateTime()
- def - toInteger()
- def - toJSValue()
- def - toNumber()
- def - toPrimitive()
- def - toQMetaObject()
- def - toQObject()
- def - toString()
- def - toUrl()
- def - toVariant()
- def - type()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - class Type¶
- This enum represents the JavaScript native types, as specified by ECMA-262 . - Constant - Description - QJSManagedValue.Type.Undefined - The - undefinedtype- QJSManagedValue.Type.Boolean - The - booleantype- QJSManagedValue.Type.Number - The - numbertype- QJSManagedValue.Type.String - The - stringtype- QJSManagedValue.Type.Object - The - objecttype- QJSManagedValue.Type.Symbol - The - symboltype- QJSManagedValue.Type.Function - The - functiontype- Note that the - nullvalue is not a type of itself but rather a special kind of object. You can query a- QJSManagedValuefor this condition using the- isNull()method. Furthermore, JavaScript has no integer type, but it knows a special treatment of numbers in preparation for integer only operations. You can query a- QJSManagedValueto find out whether it holds the result of such a treatment by using the- isInteger()method.
 - __init__()¶
 - Creates a - QJSManagedValuethat represents the JavaScript- undefinedvalue. This is the only value not stored on the JavaScript heap. Calling- engine()on a default-constructed- QJSManagedValuewill return nullptr.- Creates a - QJSManagedValuefrom- value, using the heap of- engine. If- valueis itself managed and the engine it belongs to is not- engine, the result is an- undefinedvalue, and a warning is generated.- __init__(value, engine)
- Parameters:
- value – - QJSPrimitiveValue
- engine – - QJSEngine
 
 
 - Creates a - QJSManagedValuefrom- valueusing the heap of- engine.- __init__(string, engine)
- Parameters:
- string – str 
- engine – - QJSEngine
 
 
 - Creates a - QJSManagedValuefrom- stringusing the heap of- engine.- __init__(variant, engine)
- Parameters:
- variant – object 
- engine – - QJSEngine
 
 
 - Creates a - QJSManagedValuefrom- variantusing the heap of- engine.- If this - QJSManagedValuerepresents a JavaScript FunctionObject, calls it with the given- arguments, and returns the result. Otherwise returns a JavaScript- undefinedvalue.- The - argumentshave to be either primitive values or belong to the same- QJSEngineas this- QJSManagedValue. Otherwise the call is not carried out and a JavaScript- undefinedvalue is returned.- If this - QJSManagedValuerepresents a JavaScript FunctionObject, calls it as constructor with the given- arguments, and returns the result. Otherwise returns a JavaScript- undefinedvalue.- The - argumentshave to be either primitive values or belong to the same- QJSEngineas this- QJSManagedValue. Otherwise the call is not carried out and a JavaScript- undefinedvalue is returned.- callWithInstance(instance[, arguments={}])¶
 - If this - QJSManagedValuerepresents a JavaScript FunctionObject, calls it on- instancewith the given- arguments, and returns the result. Otherwise returns a JavaScript- undefinedvalue.- The - argumentsand the- instancehave to be either primitive values or belong to the same- QJSEngineas this- QJSManagedValue. Otherwise the call is not carried out and a JavaScript- undefinedvalue is returned.- deleteProperty(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Deletes the property - namefrom this- QJSManagedValue. Returns- trueif the deletion succeeded, or- falseotherwise.- deleteProperty(arrayIndex)
- Parameters:
- arrayIndex – int 
- Return type:
- bool 
 
 - Deletes the value stored at - arrayIndexfrom this- QJSManagedValue. Returns- trueif the deletion succeeded, or- falseotherwise.- Returns the - QJSEnginethis- QJSManagedValuebelongs to. Mind that the engine is always valid, unless the- QJSManagedValueis default-constructed or moved from. In the latter case a nullptr is returned.- equals(other)¶
- Parameters:
- other – - QJSManagedValue
- Return type:
- bool 
 
 - Invokes the JavaScript ‘==’ operator on this - QJSManagedValueand- other, and returns the result.- See also - hasOwnProperty(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValuehas a property- name, otherwise returns- false. The properties of the prototype chain are not considered.- hasOwnProperty(arrayIndex)
- Parameters:
- arrayIndex – int 
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValuehas an array index- arrayIndex, otherwise returns- false. The properties of the prototype chain are not considered.- hasProperty(name)¶
- Parameters:
- name – str 
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValuehas a property- name, otherwise returns- false. The properties of the prototype chain are considered.- hasProperty(arrayIndex)
- Parameters:
- arrayIndex – int 
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValuehas an array index- arrayIndex, otherwise returns- false. The properties of the prototype chain are considered.- isArray()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a JavaScript Array object, or- falseotherwise.- isBoolean()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- boolean, or- falseotherwise.- isDate()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a JavaScript Date object, or- falseotherwise.- isError()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a JavaScript Error object, or- falseotherwise.- isFunction()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- function,- falseotherwise.- isInteger()¶
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValueholds an integer value, or- falseotherwise. The storage format of a number does not affect the result of any operations performed on it, but if an integer is stored, many operations are faster.- isJsMetaType()¶
- Return type:
- bool 
 
 - isNull()¶
- Return type:
- bool 
 
 - Returns - trueif this- QJSManagedValueholds the JavaScript- nullvalue, or- falseotherwise.- isNumber()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- number, or- falseotherwise.- isObject()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- object, or- falseotherwise.- isQMetaObject()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a QMetaObject pointer managed on the JavaScript heap, or- falseotherwise.- isQObject()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a QObject pointer managed on the JavaScript heap, or- falseotherwise.- isRegularExpression()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a JavaScript regular expression object, or- falseotherwise.- isString()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- string, or- falseotherwise.- isSymbol()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- symbol, or- falseotherwise.- isUndefined()¶
- Return type:
- bool 
 
 - Returns - trueif the type of this- QJSManagedValueis- undefined, or- falseotherwise.- isUrl()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a JavaScript Url object, or- falseotherwise.- isVariant()¶
- Return type:
- bool 
 
 - Returns - trueif this value represents a QVariant managed on the JavaScript heap, or- falseotherwise.- jsMetaInstantiate([values={}])¶
- Parameters:
- values – .list of QJSValue 
- Return type:
 
 - jsMetaMembers()¶
- Return type:
- list of strings 
 
 - jsMetaType()¶
- Return type:
 
 - Returns the property - nameof this- QJSManagedValue. The prototype chain is searched if the property is not found on the actual object.- See also - property(arrayIndex)
- Parameters:
- arrayIndex – int 
- Return type:
 
 - Returns the property stored at - arrayIndexof this- QJSManagedValue. The prototype chain is searched if the property is not found on the actual object.- prototype()¶
- Return type:
 
 - Returns the prototype for this - QJSManagedValue. This works on any value. You can, for example retrieve the JavaScript- booleanprototype from a- booleanvalue.- See also - Sets the property - nameto- valueon this- QJSManagedValue. This can only be done on JavaScript values of type- object. Furhermore,- valuehas to be either a primitive or belong to the same engine as this value.- See also - setProperty(arrayIndex, value)
- Parameters:
- arrayIndex – int 
- value – - QJSValue
 
 
 - Stores the - valueat- arrayIndexin this- QJSManagedValue. This can only be done on JavaScript values of type- object, and it’s not recommended if the value is not an array. Furhermore,- valuehas to be either a primitive or belong to the same engine as this value.- setPrototype(prototype)¶
- Parameters:
- prototype – - QJSManagedValue
 
 - Sets the prototype of this - QJSManagedValueto- prototype. A precondition is that- prototypebelongs to the same- QJSEngineas this- QJSManagedValueand is an object (including null). Furthermore, this- QJSManagedValuehas to be an object (excluding null), too, and you cannot create prototype cycles.- See also - strictlyEquals(other)¶
- Parameters:
- other – - QJSManagedValue
- Return type:
- bool 
 
 - Invokes the JavaScript ‘===’ operator on this - QJSManagedValueand- other, and returns the result.- See also - toBoolean()¶
- Return type:
- bool 
 
 - Converts the manged value to a boolean. If the managed value holds a boolean, that one is returned. Otherwise a boolean coercion by JavaScript rules is performed. - If this - QJSManagedValueholds a JavaScript Date object, returns an equivalent QDateTime. Otherwise returns an invalid one.- toInteger()¶
- Return type:
- int 
 
 - Converts the manged value to an integer. This first converts the value to a number by the rules of - toNumber(), and then clamps it into the integer range by the rules given for coercing the arguments to JavaScript bit shift operators into 32bit integers.- Internally, the value may already be stored as an integer, in which case a fast path is taken. - Note - Conversion of a managed value to a number can throw an exception. In particular, symbols cannot be coerced into numbers, or a custom valueOf() method may throw. In this case the result is 0 and the engine carries an error after the conversion. - Note - The JavaScript rules for coercing numbers into 32bit integers are unintuitive. - Copies this - QJSManagedValueinto a new- QJSValue. This is less efficient than move-constructing a- QJSValuefrom a- QJSManagedValue, but retains the- QJSManagedValue.- toNumber()¶
- Return type:
- float 
 
 - Converts the manged value to a number. If the managed value holds a number, that one is returned. Otherwise a number coercion by JavaScript rules is performed. - Note - Conversion of a managed value to a number can throw an exception. In particular, symbols cannot be coerced into numbers, or a custom valueOf() method may throw. In this case the result is 0 and the engine carries an error after the conversion. - toPrimitive()¶
- Return type:
 
 - Converts the manged value to a - QJSPrimitiveValue. If the managed value holds a type supported by- QJSPrimitiveValue, the value is copied. Otherwise the value is converted to a string, and the string is stored in- QJSPrimitiveValue.- Note - Conversion of a managed value to a string can throw an exception. In particular, symbols cannot be coerced into strings, or a custom - toString()method may throw. In this case the result is the undefined value and the engine carries an error after the conversion.- toQMetaObject()¶
- Return type:
 
 - If this - QJSManagedValueholds a QMetaObject pointer, returns it. Otherwise returns nullptr.- If this - QJSManagedValueholds a QObject pointer, returns it. Otherwise returns nullptr.- toRegularExpression()¶
- Return type:
 
 - If this - QJSManagedValueholds a JavaScript regular expression object, returns an equivalent QRegularExpression. Otherwise returns an invalid one.- toString()¶
- Return type:
- str 
 
 - Converts the manged value to a string. If the managed value holds a string, that one is returned. Otherwise a string coercion by JavaScript rules is performed. - Note - Conversion of a managed value to a string can throw an exception. In particular, symbols cannot be coerced into strings, or a custom toString() method may throw. In this case the result is an empty string and the engine carries an error after the conversion. - If this - QJSManagedValueholds a JavaScript Url object, returns an equivalent QUrl. Otherwise returns an invalid one.- toVariant()¶
- Return type:
- object 
 
 - Copies this - QJSManagedValueinto a new QVariant. This also creates a useful QVariant if- isVariant()returns false. QVariant can hold all types supported by- QJSManagedValue.- Returns the JavaScript type of this - QJSManagedValue.