Qt 6.12 LTS is out! See what's new in the release
blog
QJSEngine, how to access and change class members
-
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..