QScriptClass类

QScriptClass类
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script objects.
QScriptClass为自定义Qt Script对象提供了一个接口。
The QScriptClass class defines an interface for handling various aspects of interaction with the Qt Script objects associated with the class. Such objects are created by calling QScriptEngine::newObject(), passing a pointer to the QScriptClass as argument.
QScriptClass类为了处理Qt Script对象和关联类的各个方面定义了一个接口。通过调用newObject创建这样的对象,传递一个指向
QScriptClass的指针作为参数。
By subclassing QScriptClass, you can define precisely how access to properties of the objects that use your class is handled. This enables a fully dynamic handling of properties, e.g. it’s more powerful than QScriptEngine::newQObject(). For example, you can use QScriptClass to implement array-type objects (i.e. objects that handle the length property, and properties whose names are valid array indexes, in a special way), or to implement a “live” (runtime-defined) proxy to an underlying object.
通过子类化QScriptClass,你可以清晰地定义使用你的类的对象的属性如何被处理。这使得能够完全动态处理属性。它是更强大的比newQObject()。例如,你可以使用QScriptClass实现数组类型对象或者实现一个对基础对象”活”的代理。
If you just need to handle access to a set of properties that are known at the time an object is created (i.e. “semi-statically”), you might consider using QScriptValue::setProperty() to define getter/setter functions for the relevant properties, rather than subclassing QScriptClass.
如果你只是需要处理一组已知属性的访问在对象被创建的时候,你可能想要使用setProperty()来定义getter/setter函数为关联的属性而不是子类化QScriptClass。
Reimplement queryProperty() to specify which properties are handled in a custom way by your script class (i.e. should be delegated to the QScriptClass), and which properties should be handled just like normal Qt Script object properties.
重新实现queryProperty()来指定那些属性被处理用你自己的脚本类,那些属性应该想普通Qt Script对象属性被处理。
Reimplement property() and setProperty() to perform the actual access (read or write) to the properties that your class handles. Additionally, you can reimplement propertyFlags() to specify custom flags for your properties.
重新实现property()和setProperty()来执行对属性实际的访问在你的类处理。另外你可以重新实现propertyFlags()来为你的属性指定自定义的标志位。
Reimplement newIterator() to provide an iterator for objects of your custom class. This is only necessary if objects of your class can have custom properties that you want to be reported when an object is used together with the QScriptValueIterator class, or when an object is used in a for-in enumeration statement in a script.
重新实现newIterator()来提供一个迭代器为你自定义的对象。这仅仅是必要的如果你的类的对象有自定义属性,当一个对象和
QScriptValueIterator类在一起使用时,你想要被通知。
When implementing custom classes of objects, you typically use QScriptValue::setData() to store instance-specific data as part of object initialization; the data won’t be accessible from scripts directly, but you can access it in e.g. your reimplementations of property() and setProperty() (by calling QScriptValue::data()) to perform custom processing.
当实现自定义类的对象的时候,你可以使用setData()来存储特殊实例的数据作为对象初始化的一部分;数据将不能通过脚本直接被访问,但是你可以访问它在你重新实现的property()和setProperty()来执行自定义处理。
Reimplement prototype() to provide a custom prototype object for your script class.
重新实现prototype()来提供一个自定义原型对象为你的脚本类。
Reimplement supportsExtension() and extension() if your custom script class supports one or more of the extensions specified by the Extension enum.
重新实现supportsExtension()和extension()如果你自定义的脚本类支持一个或者多个扩展的枚举。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值