April 29, 2012

0...-5 0...-5
Lab Rat
7 posts

A problem constructing objects in a script code

 

I wrapped a function to be called as class-constructor from a scipt code:

  1. {
  2.     context->thisObject().setProperty("x", context->argument(0));
  3.     context->thisObject().setProperty("y", context->argument(1));
  4.     context->thisObject().setProperty("z", context->argument(2));
  5.     return engine->undefinedValue();
  6. }

and registed it in my engine:

  1. QScriptValue proto = engine.newQObject(new CPos());
  2. engine.setDefaultPrototype(qMetaTypeId<CPos*>(), proto);
  3. engine.globalObject().setProperty("Pos", engine.newFunction(Pos, proto));

When I tried to execute a simple script

  1. var p1 = new Pos(1, 2, 3);
  2. var p2 = new Pos(10, 20, 30);

I found p1-object properties being initialized with the second object constructor arguments – (10, 20, 30). It seem’s context->thisObject() doesn’t switch to p2. Can anybody help me with this?

0 replies

 
  ‹‹ [SOLVED] How to change the background color of selected text in QGraphicsTextItem?      QSystemDeviceInfo in Qt Desktop application ››

You must log in to post a reply. Not a member yet? Register here!