Changes between Version 5 and Version 6 of QtScript

Aug 18, 2010 6:03:06 AM (13 years ago)



  • QtScript

    v5 v6  
    249249It's possible to override QtScript's conversion of any type by registering a pair of conversion functions for the type using qScriptRegisterMetaType().
     251=== Mapping Qt Classes to JavaScript ===
     253Qt's introspection capabilities can be used to set up a JS inheritance chain that corresponds to the C++ inheritance.
     255   * QMetaObject::superClass() provides the meta-object of a class's super class.
     256   * QMetaObject::propertyOffset() provides the offset of a class's own properties. QMetaObject::propertyCount() - QMetaObject::propertyOffset() gives the number of properties defined by the class itself (i.e. not including inherited properties).
     257   * QMetaObject::methodOffset() provides the offset of a class's own methods. QMetaObject::methodCount() - QMetaObject::methodOffset() gives the number of methods defined by the class itself (i.e. not including inherited methods).
     259The idea is to define a JS class (JSClassCreate() and friends in the JSC C API) that defines the class's own properties (corresponding to C++ properties), and that inherits the JS super-class. Each JS class also has a prototype object that contains the class's own methods (corresponding to C++ methods).
     261Example: QPushButton; see (This would probably work better as a diagram:)
     263   * JSClass(QPushButton).properties = autoDefault, default, flat
     264   * JSPrototype(QPushButton).properties = showMenu
     265   * JSPrototype(QPushButton).__proto__ = JSPrototype(QAbstractButton)
     266   * JSClass(QPushButton).superClass = JSClass(QAbstractButton)
     268   * JSClass(QAbstractButton).properties = autoExclusive, autoRepeat, ...
     269   * JSPrototype(QAbstractButton).properties = animateClick, click, setChecked, setIconSize, toggle
     270   * JSPrototype(QAbstractButton).__proto__ = JSPrototype(QWidget)
     271   * JSClass(QAbstractButton).superClass = JSClass(QWidget)
     273... and so on, all the way down to QObject.
     275These class definitions and prototype objects can be created on demand, and cached so that they can be shared by all wrapped objects of the same type.