I’ve got a custom QML object called Target.qml. I would like to create dynamic instances of this object using Qt.createQmlObject().
It works when using builtin qml objects like Image:
var newTarget = Qt.createQmlObject('import Qt 4.7; Image {source: "widgets/SlideSwitchImages/knob.png"; }', parent);
But fails when using any custom object types like:
var newTarget = Qt.createQmlObject('import Qt 4.7; Target {}', parent);
If however I use my custom Target type statically in QML everything works. Is this a known limitation, any workarounds?
If you just need an arbitrary number of Target instances it would be better to use Component.
However if you want to stick to the Qt.createQmlObject call I guess you have the Target component in a different directory and you’re just missing out some import statement. The string parameter must be the content of a QML file that works on its own in the same directory as the one calling it.
E.g.
BTW: The Qt 4.7 imports are deprecated because they don’t allow additional versions of QtQuick.