Changes between Version 5 and Version 6 of QtScript


Ignore:
Timestamp:
Aug 18, 2010, 6:03:06 AM (14 years ago)
Author:
kent.hansen@nokia.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • QtScript

    v5 v6  
    248248
    249249It's possible to override QtScript's conversion of any type by registering a pair of conversion functions for the type using qScriptRegisterMetaType().
     250
     251=== Mapping Qt Classes to JavaScript ===
     252
     253Qt's introspection capabilities can be used to set up a JS inheritance chain that corresponds to the C++ inheritance.
     254
     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).
     258
     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).
     260
     261Example: QPushButton; see http://doc.trolltech.com/4.6/qpushbutton.html. (This would probably work better as a diagram:)
     262
     263   * JSClass(QPushButton).properties = autoDefault, default, flat
     264   * JSPrototype(QPushButton).properties = showMenu
     265   * JSPrototype(QPushButton).__proto__ = JSPrototype(QAbstractButton)
     266   * JSClass(QPushButton).superClass = JSClass(QAbstractButton)
     267
     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)
     272
     273... and so on, all the way down to QObject.
     274
     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.