[Qtscript-bindings] QScriptValue::isFunction() in 4.5

syntheticpp at gmx.net syntheticpp at gmx.net
Wed Jan 7 13:10:30 CET 2009


-------- Original-Nachricht --------
> Datum: Tue, 06 Jan 2009 16:03:18 +0100
> Von: Kent Hansen <khansen at trolltech.com>
> An: qtscript-bindings at kde.org
> Betreff: Re: [Qtscript-bindings] QScriptValue::isFunction() in 4.5

> syntheticpp at gmx.net wrote:
> >> Right, QObject doesn't implement hasInstance(). Of the built-in object
> >> types only Function implements hasInstance(). With Qt 4.5 you can
> >> implement it for custom types (see
> >> http://doc.trolltech.com/main-snapshot/qscriptclass.html#extension).
> >> It sounds like your script is applying the instanceof operator to an
> >> object created with QScriptEngine::newQObject(). I'm sorry that it
> >> breaks now, but it should never have been working in the first place.
> >> :-( Maybe you can share some more information on what the script is
> >> doing, then it's easier to suggest a proper solution.
> >>     
> >
> > OK, the patch is wrong. And you are right, I use newQObject() with a 
> > QScriptable object as constructor.
> >   
> 
> Why is the QScriptable object used as a constructor? You can't actually
> call it to construct objects.
> 
> > It seems I have too redesign this code and to use a simple creator
> function, or
> > do you know a better way. (I've tried so set the prototype of the ctor
> object
> > to Function.prototype, but this doesn't help either)
> >
> > Peter
> >
> >   
> 
> Right, setting the prototype won't help because the object has to
> implement [[HasInstance]] before any other conditions (i.e. the
> prototype object) are considered.
> If you really want to keep the current design (i.e. have the actual
> script work as before) you could subclass QScriptClass, implement the
> HasInstance extension, and have the QScriptClass instance be a proxy to
> the QScriptable object. Not something I would ordinarily do, though. ;-)
> If you don't want to change the constructor to be a normal function,
> maybe the QScriptable can have an isA() function that scripts should use
> instead of the instanceof operator?
> 
> Regards,
> Kent

Best is to redesign my current code.

Thanks,
Peter
-- 
Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a


More information about the Qtscript-bindings mailing list