Type casting in QtScript.



  • I have a class hierarchy

    @
    class A
    {

    public:

    QList<A*> list()
    {
         return _list;
    }
    

    protected:

    QList<A*> _list;

    };

    class B : public A
    {
    B()
    {
    _list.push_back(this);
    }
    };
    @

    Both classes are not QObject descendants.

    I expose both classes to QtScript using QScriptable classes and QScriptEngine::setDefaultPrototype() method. Method list() is exposed to QtScript.

    When I call list() from JavaScript I get a collection of pointers to class A, but among them I have pointers to class B. How I can cast those pointers to B* in JavaScript? Or maybe it is possible to change A* prototype to B* prototype? Maybe it is possible to write some function to do that in C++.

    Does somebody have any ideas how to solve the problem?

    Thanks,
    MIchael

    [EDIT: code formatting, please use @-tags, Volker]


Log in to reply
 

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