PDA

View Full Version : QtScript QPoint



bunjee
17th May 2009, 22:41
Hi trolls,

I'm trying to make a QPoint newable and modifyable from QtScript.

I've defined the "QPoint ctor" and "QPoint::setX" function in my script.
The QPoint constructs properly, but I can't seem to find the proper
implementation for setX(int x);


inline QScriptValue QPoint_setX(QScriptContext *ctx, QScriptEngine *eng)
{
QPoint object = ctx->thisObject().toVariant().toPoint();

if (ctx->argumentCount() == 1 && ctx->argument(0).isNumber())
{
object.setX(ctx->argument(0).toInt32());

// This doesn't seem to apply changes
ctx->setThisObject(eng->newVariant(object));
}
return eng->undefinedValue();
}

Is it possible to do such a thing ?

wysota
18th May 2009, 20:06
You should return the new value.


inline QScriptValue QPoint_setX(QScriptContext *ctx, QScriptEngine *eng)
{
QPoint object = ctx->thisObject().toVariant().toPoint();

if (ctx->argumentCount() == 1 && ctx->argument(0).isNumber())
{
object.setX(ctx->argument(0).toInt32());
return eng->newVariant(object);
}
return eng->undefinedValue();
}

bunjee
27th May 2009, 09:33
The answere here:
http://doc.trolltech.com/4.5/qtscript.html#implementing-prototype-objects-for-value-based-types