QtScript: using methods from prototype of derived class



  • I have two prototypes:
    @
    class QWidgetPrototype : public QObject, public QScriptable
    {
    ...
    Q_INVOKABLE void move(int x, int y);
    };

    class QLabelPrototype : public QObject, public QScriptable
    {
    ...
    Q_INVOKABLE void setText(QString text);
    };

    ...

    QWidgetPrototype widgetProto;
    QLabelPrototype labelProto;
    Q_DECLARE_METATYPE(QWidget *)
    Q_DECLARE_METATYPE(QLabel *)
    ...
    engine->setDefaultPrototype(qMetaTypeId<QWidget *>(), engine->newQObject(&widgetProto;));
    engine->setDefaultPrototype(qMetaTypeId<QLabel *>(), engine->newQObject(&labelProto));
    @

    So in QtScript I can do something like that:
    @
    var widget = myWindowt.findChild("someWidget");
    widget.move(100, 50);

    var label = myWindowt.findChild("helloLabel");
    label.setText("Hello there!");
    ...
    @

    But this doesn't work:
    @
    label.move(20, 30);
    ^TypeError: Result of expression 'label.move' [undefined] is not a function.
    @

    Because QLabel inherits QWidget I thought I could use the same methods from QWidgetPrototype on QLabelPrototype. Is it possible to typecast label to QPushButton inside QtScript?

    EDIT: I found that the same problem described here: http://developer.qt.nokia.com/forums/viewthread/5082


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.