QScriptClass Class Reference |
Constant | Value | Description |
---|---|---|
QScriptClass::Callable | 0 | Instances of this class can be called as functions. |
See also extension().
This enum describes flags that are used to query a QScriptClass regarding how access to a property should be handled.
Constant | Value | Description |
---|---|---|
QScriptClass::HandlesReadAccess | 0x01 | The QScriptClass handles read access to this property. |
QScriptClass::HandlesWriteAccess | 0x02 | The QScriptClass handles write access to this property. |
The QueryFlags type is a typedef for QFlags<QueryFlag>. It stores an OR combination of QueryFlag values.
See also queryProperty().
Constructs a QScriptClass object to be used in the given engine.
The engine does not take ownership of the QScriptClass object.
Destroys the QScriptClass object.
If a QScriptClass object is deleted before the associated engine(), any Qt Script objects using the QScriptClass will be "demoted" to normal Qt Script objects.
Returns the engine that this QScriptClass is associated with.
This virtual function can be reimplemented in a QScriptClass subclass to provide support for extensions. The optional argument can be provided as input to the extension; the result must be returned in the form of a QVariant. You can call supportsExtension() to check if an extension is supported by the QScriptClass. By default, no extensions are supported, and this function returns an invalid QVariant.
If you implement the Callable extension, Qt Script will call this function when an instance of your class is called as a function (e.g. from a script or using QScriptValue::call()). The argument will contain a pointer to the QScriptContext that represents the function call, and you should return a QVariant that holds the result of the function call. In the following example the sum of the arguments to the script function are added up and returned:
if (extension == Callable) { QScriptContext *context = qvariant_cast<QScriptContext*>(argument); QScriptEngine *engine = context->engine(); double sum = 0; for (int i = 0; i < context->argumentCount(); ++i) sum += context->argument(i).toNumber(); return sum; }
See also supportsExtension().
Returns the name of the script class.
Qt Script uses this name to generate a default string representation of objects in case you do not provide a toString function.
The default implementation returns a null string.
Returns an iterator for traversing custom properties of the given object.
The default implementation returns 0, meaning that there are no custom properties to traverse.
Reimplement this function if objects of your script class can have one or more custom properties (e.g. those reported to be handled by queryProperty()) that you want to appear when an object's properties are enumerated (e.g. by a for-in statement in a script).
Qt Script takes ownership of the new iterator object.
See also QScriptValueIterator.
Returns the value of the property with the given name of the given object.
The id argument is only useful if you assigned a value to it in queryProperty().
The default implementation does nothing and returns an invalid QScriptValue.
See also setProperty() and propertyFlags().
Returns the flags of the property with the given name of the given object.
The id argument is only useful if you assigned a value to it in queryProperty().
The default implementation returns 0.
See also property().
Returns the object to be used as the prototype of new instances of this class (created with QScriptEngine::newObject()).
The default implementation returns an invalid QScriptValue, meaning that the standard Object prototype will be used. Reimplement this function to provide your own custom prototype.
Typically you initialize your prototype object in the constructor of your class, then return it in this function.
See the "Making Use of Prototype-Based Inheritance" section in the QtScript documentation for more information on how prototypes are used.
Queries this script class for how access to the property with the given name of the given object should be handled. The given flags specify the aspects of interest. This function should return a subset of flags to indicate which aspects of property access should be further handled by the script class.
For example, if the flags contain HandlesReadAccess, and you would like your class to handle the reading of the property (through the property() function), the returned flags should include HandlesReadAccess. If the returned flags do not contain HandlesReadAccess, the property will be handled as a normal script object property.
You can optionally use the id argument to store a value that will subsequently be passed on to functions such as property() and setProperty().
The default implementation of this function returns 0.
Note: This function is only called if the given property isn't already a normal property of the object. For example, say you advertise that you want to handle read access to property foo, but not write access; if foo is then assigned a value, it will become a normal script object property, and subsequently you will no longer be queried regarding read access to foo.
See also property().
Sets the property with the given name of the given object to the given value.
The id argument is only useful if you assigned a value to it in queryProperty().
The default implementation does nothing.
An invalid value represents a request to remove the property.
See also property().
Returns true if the QScriptClass supports the given extension; otherwise, false is returned. By default, no extensions are supported.
Reimplement this function to indicate which extensions your custom class supports.
See also extension().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com