Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtScript: using methods from prototype of derived class

QtScript: using methods from prototype of derived class

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svlasov
    wrote on 21 Sept 2011, 11:31 last edited by
    #1

    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

    1 Reply Last reply
    0

    1/1

    21 Sept 2011, 11:31

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved