Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QJSEngine, how to access and change class members
Qt 6.12 LTS is out! See what's new in the release blog

QJSEngine, how to access and change class members

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 443 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.
  • mhsgoudM Offline
    mhsgoudM Offline
    mhsgoud
    wrote on last edited by
    #1

    Hi, I am trying to write a simple scripting widget, where user can change variables of a qt class.
    I did the following to expose a qt class to JS:

    QJSEngine engine;
    QJSValue objectValue = engine.newQObject(this->mThread);
    engine.globalObject().setProperty("myObject", objectValue);
    

    my problem is that this:

    qDebug() << "Number is:" << engine.evaluate("myObject.tess_ ").toNumber();
    

    gives nan. even though variable tess_ has been initiated in my mThread class constructor.

    Also, by setting

    engine.evaluate("myObject.tess_ = 5 ") ;
    

    the value of class does not seem to change by calling:

    qDebug() << this->mThread->tess_ ;
    

    I appreciate any help. also on how to make changes interactive, as one would expect in similar situations..

    1 Reply Last reply
    0
    • mhsgoudM Offline
      mhsgoudM Offline
      mhsgoud
      wrote on last edited by
      #2

      bringing this up, any suggestion? interesting is that when I evaluate a function, the class members get updated. but if I directly change a member with evaluate, it is not changed in c++ code!!

      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