[Qt-interest] QScriptValue::setPrototype doens't work in Qt4.6?

Kent Hansen khansen at trolltech.com
Tue Dec 29 14:48:22 CET 2009


Hi,
Method 3 works here after I modify your queryProperty() to return 
Handles{Read,Write}Access.
But if the other methods work with 4.5 but not with 4.6, that sounds 
like unintended regressions. I recommend creating a task at 
bugreports.qt.nokia.com.

Regards,
Kent



Dong Tiger skrev:
> Sorry, the sample code should be as following. And I've verified that 
> method 1-4 work with Qt4.5.
>
> #include <QScriptEngine>
> #include <QCoreApplication>
> #include <QScriptClass>
> #include <QtDebug>
>
> class ResolveClass : public QScriptClass {
>  public:
>   ResolveClass(QScriptEngine *engine) : QScriptClass(engine) {}
>   QScriptValue property(const QScriptValue &obj, const QScriptString 
> &name, uint id) {
>     qDebug() << name;
>     return QScriptValue();
>   }
>   QueryFlags queryProperty(const QScriptValue &obj, const 
> QScriptString &name, QueryFlags flags, uint *id) {
>     qDebug() << name;
>     return 0;
>   }
> };
>
> int main(int argc, char **argv) {
>   QCoreApplication app(argc, argv);
>   QScriptEngine engine;
>   ResolveClass resolve_class(&engine);
>
>   // method1: doesn't work.
>   // engine.globalObject().setScriptClass(&resolve_class);
>
>   // method2: doesn't work.
>   // engine.globalObject().setPrototype(engine.newObject(&resolve_class));
>
>   // method3: doesn't work.
>   // engine.setGlobalObject(engine.newObject(&resolve_class));
>
>   // method4: doesn't work.
>   // QScriptValue global = engine.newObject();
>   // global.setPrototype(engine.newObject(&resolve_class));
>   // engine.setGlobalObject(global);
>
>   // This works but not what I need.
>   QScriptValue global = engine.newObject();
>   global.setProperty("b", 200);
>   engine.setGlobalObject(global);
>
>   engine.evaluate("var a = 100; a = b;");
>   QScriptValue a = engine.globalObject().property("a");
>   qDebug() << a.toInt32() << "\n";
>   return 0;
> }
>
>
> 2009/12/28 Dong Tiger <idlecat511 at gmail.com <mailto:idlecat511 at gmail.com>>
>
>     Hi,
>
>     My code that works with Qt4.5 doesn't work with 4.6. I wrote a
>     short code to demonstrate the problem. What I want to do is trying
>     to get ResolveClass::property being called when a global variable
>     b is referred.
>
>     #include <QCoreApplication>
>     #include <QScriptEngine>
>     #include <QScriptClass>
>     #include <QtDebug>
>
>     class ResolveClass : public QScriptClass {
>      public:
>       ResolveClass(QScriptEngine *engine) : QScriptClass(engine) {}
>       QScriptValue property(const QScriptValue &obj, const
>     QScriptString &name, uint id) {
>         qDebug() << name;
>       }
>     };
>
>     int main(int argc, char **argv) {
>       QCoreApplication app(argc, argv);
>       QScriptEngine engine;
>       ResolveClass resolve_class(&engine);
>
>       // method1: doesn't work.
>       // engine.globalObject().setScriptClass(&resolve_class);
>
>       // method2: works with 4.5 but not with 4.6.
>       //
>     engine.globalObject().setPrototype(engine.newObject(&resolve_class));
>
>       // method3: doesn't work.
>       // engine.setGlobalObject(engine.newObject(&resolve_class));
>
>       // method4: doesn't work.
>       // QScriptValue global = engine.newObject();
>       // global.setPrototype(engine.newObject(&resolve_class));
>       // engine.setGlobalObject(global);
>
>       // This works but not what I need.
>       QScriptValue global = engine.newObject();
>       global.setProperty("b", 200);
>       engine.setGlobalObject(global);
>
>       engine.evaluate("var a = 100; a = b;");
>       QScriptValue a = engine.globalObject().property("a");
>       qDebug() << a.toInt32() << "\n";
>       return 0;
>     }
>
>     I don't have Qt4.5 at hand so I didn't verify if these methods
>     work with Qt4.5 except method2.
>     Any  idea of that? Thanks in advance.
>
>     --
>     Tiger
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   




More information about the Qt-interest-old mailing list