One difference to my working prototypes is the constructor. Translated to your class it would be:
QScriptValue WidgetPrototype::construct(QScriptContext *ctx, QScriptEngine *eng)
{
if(ctx->argumentCount()==0)
{
// use newQObject; script ownership
return eng
->newQObject
(new QWidget(), QScriptEngine
::ScriptOwnership);
}
return eng->undefinedValue();
}
QScriptValue WidgetPrototype::construct(QScriptContext *ctx, QScriptEngine *eng)
{
if(ctx->argumentCount()==0)
{
// use newQObject; script ownership
return eng->newQObject(new QWidget(), QScriptEngine::ScriptOwnership);
}
return eng->undefinedValue();
}
To copy to clipboard, switch view to plain text mode
Other differences:
// prototype object not on stack:
WidgetPrototype* WidgetPrototypeObject = new WidgetPrototype();
// make it script owned:
QScriptValue widgetProto = engine.newQObject(WidgetPrototypeObject, QScriptEngine::ScriptOwnership);
engine.setDefaultPrototype(qMetaTypeId<QWidget*>(), widgetProto);
QScriptValue widgetCtor = engine.newFunction(WidgetPrototype::construct, widgetProto);
engine.globalObject().setProperty("Widget", widgetCtor);
// prototype object not on stack:
WidgetPrototype* WidgetPrototypeObject = new WidgetPrototype();
// make it script owned:
QScriptValue widgetProto = engine.newQObject(WidgetPrototypeObject, QScriptEngine::ScriptOwnership);
engine.setDefaultPrototype(qMetaTypeId<QWidget*>(), widgetProto);
QScriptValue widgetCtor = engine.newFunction(WidgetPrototype::construct, widgetProto);
engine.globalObject().setProperty("Widget", widgetCtor);
To copy to clipboard, switch view to plain text mode
Bookmarks