Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScriptContext thisObject in custom include function

QScriptContext thisObject in custom include function

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.8k 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.
  • F Offline
    F Offline
    feldifux
    wrote on last edited by
    #1

    Hi,
    I have a question regarding thisObject & activationObject in QScriptContext:
    I have written a custom include function to allow including other script files from custom script files, similar to the code in QScriptContext documentation: http://developer.qt.nokia.com/doc/qt-4.8/qscriptcontext.html#details

    This is the code from the doc:
    @QScriptValue myInclude(QScriptContext *ctx, QScriptEngine *eng)
    {
    QString fileName = ctx->argument(0).toString();
    QString contents = readTheFile(fileName);
    ctx->setActivationObject(ctx->parentContext()->activationObject());
    ctx->setThisObject(ctx->parentContext()->thisObject());
    return eng->evaluate(contents, fileName);
    }@

    However, after I set the thisObject and activationObject to the one of the parent context, they are undefined in the functions I call in the included script. After looking at the context backtrace, it turns out that a new <eval> context is added with the correct thisObject applied, but the top-most context has no thisObject and acitivationObject assigned.

    So to sum it up, if i set a QObject as thisObject for script A and include script B from A, I can NOT access the properties of my QObject from B. Instead I get an assertion stating the thisObject is not a qobject:

    ASSERT failure in QTJSC::JSValue QScript::QtPropertyFunction::execute(QTJSC::ExecState*, QTJSC::JSValue, const QTJSC::ArgList&): "this-object must be a QObject", file bridge\qscriptqobject.cpp, line 1085

    I hope anybody can help,
    Chris

    Founder of Felgo SDK - http://felgo.com/qt

    Felgo simplifies

    • Mobile App Dev with Qt esp. iOS & Android
    • Game Development with Qt

    What others say

    Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

    1 Reply Last reply
    0
    • F Offline
      F Offline
      feldifux
      wrote on last edited by
      #2

      After further investigating this issue, it gets even more unclear what its cause or solution might be. The following example demonstrates its effect:

      Suppose to have 2 script files: A.js and B.js. Script A includes B and calls functions of B:

      B.js:
      @function test1() {
      print("test1.this: " + this);
      test2();
      }

      function test2() {
      print("test2.this: " + this);
      }@

      A.js:
      @include("B.js");
      test2(); // outputs test2.this correctly
      test1(); // outputs test1.this correctly, BUT causes an exception in test2 because this is not known there!?!@

      Might this be a Qt bug?

      Founder of Felgo SDK - http://felgo.com/qt

      Felgo simplifies

      • Mobile App Dev with Qt esp. iOS & Android
      • Game Development with Qt

      What others say

      Felgo scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

      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 Extensions
      • Unsolved