Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A problem constructing objects in a script code
Qt 6.11 is out! See what's new in the release blog

A problem constructing objects in a script code

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    0...-5
    wrote on last edited by
    #1

    I wrapped a function to be called as class-constructor from a scipt code:
    @QScriptValue Pos(QScriptContext *context, QScriptEngine *engine)
    {
    context->thisObject().setProperty("x", context->argument(0));
    context->thisObject().setProperty("y", context->argument(1));
    context->thisObject().setProperty("z", context->argument(2));
    return engine->undefinedValue();
    }@

    and registed it in my engine:

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

    When I tried to execute a simple script
    @var p1 = new Pos(1, 2, 3);
    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved