When I use Qt.createComponent to create component dynamically, the stutas is always Component.error but I cannot understand the reason.
I used it like that:
Rectangle{
function loadTest(){
function finishCreation() {
if (component.status === Component.Ready) {
console.log("ready")
} else if (component.status === Component.Error) {
// Error Handling
console.log("Error loading component:", component.errorString());
}
}
var component = Qt.createComponent("MyPage.qml");
console.log(component.status)
console.log("Error loading component:", component.errorString());
component.statusChanged.connect(finishCreation);
if (component.status === Component.Ready) {
var button = component.createObject(container);
console.log("ready")
}
}
Component.onCompleted: {
console.log("Completed Running!")
loadTest()
}
}
If the MyPage.qml does not exist in the qrc file, the error is
qrc:/MyPage.qml:-1 File not found"
If I set the full path of MyPage.qml, I get a Network error.
When I add the SeriesSelectionPage.qml file to the resource file, it works. But it shouldn't be dynamic?
I just want to find a QML file and load it dynamically when the application executes so that the application can load different QML according to user operations.
Anyone knows how to do that? I'm going crazy.