Unsolved How to find registered qml types from c++ with public api ?
-
Hi, im writing system monitor like application, for which user can define its layout. From json property i instantiate qml object and set properties for it. I would like to give my users access to built in qml types (rectangle, item and so on).
-
Is there way to create these qml types from c++ by name?
-
Also is there way to find all registered qml types ? I'm planning to create simple wysiwyg editor, which would create json for users and i would like to show there qml types also. I know there is private api i can use. But i would be glad if it is posible to make only with public api.
Ps: I know i could create qml from given json or make user create qml themselves but i dont want to do that.
-
-
@Kwan said in How to find registered qml types from c++ with public api ?:
Is there way to create these qml types from c++ by name?
not directly.
But for simple tasks you could do something like that:QQmlComponent component(engine); component.setData( "import QtQuick 2.0" "\n" "Rectangle {" "\n" "}" ); QQuickItem *rectItem= qobject_cast<QQuickItem*>(component.create()); QQmlProperty::write(rectItem, "width", QVariant::fromValue<qreal>(100.0)); QQmlProperty::write(rectItem, "height", QVariant::fromValue<qreal>(50.0));
-
@Kwan said in How to find registered qml types from c++ with public api ?:
Also is there way to find all registered qml types ?
depends what module you do import.
You can parse the .qmltypes files (e.g. <QTDIR>/qml/QtQuick.2/plugins.qmltypes) which expose all types the plugin/module provides.