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. QObject children and dynamic properties in QJSEngine
Forum Updated to NodeBB v4.3 + New Features

QObject children and dynamic properties in QJSEngine

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 798 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.
  • X Offline
    X Offline
    Xilexio
    wrote on last edited by
    #1

    According to QJSEngine documentation, I should be able to access "properties, children, and signals and slots of the QObject are available as properties of the proxy object" (QJSValue). However that doesn't seem to be the case.

    I created object obj and another (named) object child with obj as parent. I also set dynamic property of object obj. I can't access object's child and I can't access the dynamic property, as shown in the following snippet:

    @QJSEngine engine;
    auto *obj = new QObject;
    auto *child = new QObject(obj);
    child->setObjectName("child");

    auto sObj = engine.newQObject(obj);
    engine.globalObject().setProperty("obj", sObj);

    obj->setProperty("prop", 42);

    qDebug() << sObj.property("child").toString();
    qDebug() << sObj.property("obj").property("prop").toString();
    qDebug() << engine.evaluate("var x = ''; for (var p in obj) { x += p + ' '; }; x").toString();@

    The output is:
    @"undefined"
    "undefined"
    "objectName destroyed destroyed objectNameChanged deleteLater _q_reregisterTimers "@

    I would expect it to be some string representing child object in the first line (like for other objects), "42" in the second line and contain "prop" and "child" in the third line.

    Am I doing something wrong or, unlike in QtScript, you can't access children and dynamic properties of an object through JS properties?

    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