Okay, i could fix it by my own. My mistake was the usage of the out-of-box macro Q_SCRIPT_DECLARE_QMETAOBJECT() (Qt 4.8.1)
There is nothing wrong with it, despite the fact, that behind this macro, there is a boiler plate constructor for script objects which does not set the default prototype! Maybe you could see this as a bug? I don't know.
But more important, to use the defaultPrototype feature in the way I used it above, either you have to define your own constructor for script objects or, a more elegant way, define your own Q_SCRIPT_DECLARE_QMETAOBJECT() macro. Below there is my suggestion with defaultPrototype-Support:
original Q_SCRIPT_DECLARE_QMETAOBJECT() macro:
@
#define Q_SCRIPT_DECLARE_QMETAOBJECT(T, _Arg1)
template<> inline QScriptValue qscriptQMetaObjectConstructor<T>(QScriptContext *ctx, QScriptEngine *eng, T )
{
_Arg1 arg1 = qscriptvalue_cast<_Arg1> (ctx->argument(0));
T t = new T(arg1);
if (ctx->isCalledAsConstructor())
return eng->newQObject(ctx->thisObject(), t, QScriptEngine::AutoOwnership);
QScriptValue o = eng->newQObject(t, QScriptEngine::AutoOwnership);
o.setPrototype(ctx->callee().property(QString::fromLatin1("prototype")));
return o;
}
@
improved suggestion with defaultPrototype-support:
@
#define Q_SCRIPT_DECLARE_QMETAOBJECT_DEFAULT_PROTOTYPE(T, _Arg1)
template<> inline QScriptValue qscriptQMetaObjectConstructor<T>(QScriptContext *ctx, QScriptEngine eng, T )
{
_Arg1 arg1 = qscriptvalue_cast<_Arg1> (ctx->argument(0));
T t = new T(arg1);
if (ctx->isCalledAsConstructor()) {
QScriptValue proto = eng->defaultPrototype(qMetaTypeId<T>());
QScriptValue u = eng->newQObject(ctx->thisObject(), t, QScriptEngine::AutoOwnership);
u.setPrototype(proto);
return u;
}
QScriptValue o = eng->newQObject(t, QScriptEngine::AutoOwnership);
o.setPrototype(ctx->callee().property(QString::fromLatin1("prototype")));
return o;
}
@
All needed voodoo is to ask the ScriptEngine for the defaultPrototype using the template parameter T (line 7) and setting it as prototype of the newly created script object (line 9)
Maybe it is useful for someone out there!