Hi,
If I understand correctly you want to load some components dynamically, right? If so you can read this document.
Also you can use Loder component for load QML file dynamically. This component can be use for load qml files from local resource or from public server.
In my application I use this methods for load qml components dynamically:
/** @brief Create dynamic object from QML file.
* @param qml Path to QML file.
* @param parent Parent instance.
* @param options List of options fields.
* @param onComplete Callback function which will call when qml component will be loaded.*/
function createComponentFromQMLFile(qml, parent, options, onComplete) {
if(qml !== null && qml !== undefined && qml.length > 0 &&
parent !== null && parent !== undefined &&
options !== null && options !== undefined &&
onComplete !== null && onComplete !== undefined && onComplete instanceof Function) {
var tmp = Qt.createComponent(qml);
if(tmp !== null) {
if(tmp.status === Component.Ready) {
var itemInstance = tmp.createObject(parent, options);
if(itemInstance !== null) {
onComplete(itemInstance);
} else {
console.log("[EditorHelper] ERROR: Can't create object.");
onComplete(null);
}
} else if (tmp.status === Component.Error) {
console.log("[EditorHelper] ERROR: "+tmp.errorString());
onComplete(null);
} else {
tmp.statusChanged.connect(function () {
if (tmp.status === Component.Ready) {
var item = tmp.createObject(parent, options);
if(item !== null) {
onComplete(item);
} else {
console.log("[EditorHelper] ERROR: Can't create object.");
onComplete(null);
}
} else if (tmp.status === Component.Error) {
console.log("[EditorHelper] ERROR: "+tmp.errorString());
onComplete(null);
}
});
}
} else {
console.log("[EditorHelper] ERROR: Can't load QML file '"+qml+"'.");
onComplete(null);
}
} else {
console.log("[EditorHelper] ERROR: Incorrect parameters.");
onComplete(null);
}
}
usnig like this:
options = {}; //here you can set any properties from you qml object which need to create.
var qml = "qrc:/qml/Components/ErrorMessageWindow.qml"; //Path to qml file from resources for load.
//appRootWnd - parent element to which you want to add you dynamic object.
EditorHelper.createComponentFromQMLFile(qml, appRootWnd, options, function(wnd) {
//here you can set any code which was called when objections will be created and loaded.
if(wnd) {
wnd.open();
}
});