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. How to use QJSEngine to access a child of a QObject in js script?
Forum Updated to NodeBB v4.3 + New Features

How to use QJSEngine to access a child of a QObject in js script?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 461 Views
  • 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.
  • R Offline
    R Offline
    rickluo
    wrote on last edited by rickluo
    #1

    From the official qt doc, it says:

    Signals and slots, properties and children of object are available as properties of the created QJSValue.
    

    So I expect to access the children of a QObject, but I do not find the right way to do it.

    I have code as below:

        QWidget parent;
        QLabel label(&parent);
        label.setText("Hello World");
        QJSEngine engine;
        QJSValue jsv = engine.newQObject(&parent);
    
        engine.globalObject().setProperty("w", jsv);
    
        qDebug() << engine.evaluate("JSON.stringify(w);").toString();
    
       // qDebug() << engine.evaluate("w.myLabel.text").toString(); // Does not work, how to access myLabel.text in script
    

    The debug output is as below, and I cannot find the child label information (eg. the text "Hello World") in this output. So, my question is how to access the QLabel (objectName: "myLabel") in js script?

    {
        "objectName": "",
        "modal": false,
        "windowModality": 0,
        "enabled": true,
        "geometry": {},
        "frameGeometry": {},
        "normalGeometry": {},
        "x": 0,
        "y": 0,
        "pos": {},
        "frameSize": {},
        "size": {},
        "width": 640,
        "height": 480,
        "rect": {},
        "childrenRect": {},
        "childrenRegion": {},
        "sizePolicy": {},
        "minimumSize": {},
        "maximumSize": {},
        "minimumWidth": 0,
        "minimumHeight": 0,
        "maximumWidth": 16777215,
        "maximumHeight": 16777215,
        "sizeIncrement": {},
        "baseSize": {},
        "palette": {},
        "font": {},
        "cursor": {},
        "mouseTracking": false,
        "isActiveWindow": false,
        "focusPolicy": 0,
        "focus": false,
        "contextMenuPolicy": 1,
        "updatesEnabled": true,
        "visible": false,
        "minimized": false,
        "maximized": false,
        "fullScreen": false,
        "sizeHint": {},
        "minimumSizeHint": {},
        "acceptDrops": false,
        "windowTitle": "",
        "windowIcon": {},
        "windowIconText": "",
        "windowOpacity": 1,
        "windowModified": false,
        "toolTip": "",
        "toolTipDuration": -1,
        "statusTip": "",
        "whatsThis": "",
        "accessibleName": "",
        "accessibleDescription": "",
        "layoutDirection": 0,
        "autoFillBackground": false,
        "styleSheet": "",
        "locale": {},
        "windowFilePath": "",
        "inputMethodHints": 0
    }
    
    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