I'm using a QJSEngine
to make an application scriptable. I'd like the JavaScript side to be able to modify the user interface. My main issue right now is accessing the Qt API from JavaScript.
To create widgets, I added a createWidget()
wrapper that uses QUILoader
:
// JavaScript
var w = helpers.createWidget("QPushButton");
// C++
QJSValue helpers::createWidget(QString type)
{
QUILoader ld;
return engine.newQObject(ld.createWidget(type));
}
I've also registered all the enums from qt_getQtMetaObject()
, which seems to take care of all the namespace-level enums from qnamespace.h
. It doesn't look like it's part of the public API though.
Am I really supposed to this stuff manually or am I missing something? Isn't there a registerAllTheThings()
function that creates a global Qt
object through which the Qt API available?
If there isn't, then I have a problem. I can create QWidget
s with a QUILoader
, but I couldn't find a way of creating other objects, such as a QStandardItemModel
. I thought all Qt classes would already be registered through qRegisterMetaType()
, but they're not: QMetaType::type("QStandardItemModel")
fails by returning UnknownType
. Again, am I missing some initialization function call that registers everything?