Can I expose an already existing QMainWindow and access all its children from a .js script?
QtJSAPI usage
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
QtJSAPI usage
From a developer:
Re: QtJSAPI usage
Yes. You can expose existing QObject objects as you normally would:
In JS, you can then use:
or for example:
Code: Select all
QJSEngine* engine = new QJSEngine();
RJSApi* rjsapi = new RJSApi(engine);
// this makes the Qt classes known to the script engine:
rjsapi->init();
QJSValue global = engine->globalObject();
global.setProperty("appWin", engine->newQObject(appWin));
QQmlEngine::setObjectOwnership(appWin, QQmlEngine::CppOwnership);
Code: Select all
var w = appWin.findChild('NameOfChild');
Code: Select all
var children = appWin.children();