A problem constructing objects in a script code



  • I wrapped a function to be called as class-constructor from a scipt code:
    @QScriptValue Pos(QScriptContext *context, QScriptEngine *engine)
    {
    context->thisObject().setProperty("x", context->argument(0));
    context->thisObject().setProperty("y", context->argument(1));
    context->thisObject().setProperty("z", context->argument(2));
    return engine->undefinedValue();
    }@

    and registed it in my engine:

    @QScriptValue proto = engine.newQObject(new CPos());
    engine.setDefaultPrototype(qMetaTypeId<CPos*>(), proto);
    engine.globalObject().setProperty("Pos", engine.newFunction(Pos, proto));@

    When I tried to execute a simple script
    @var p1 = new Pos(1, 2, 3);
    var p2 = new Pos(10, 20, 30);@

    I found p1-object properties being initialized with the second object constructor arguments - (10, 20, 30). It seem's context->thisObject() doesn't switch to p2. Can anybody help me with this?


Log in to reply
 

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