qtqmlqqmlcomponent

Is there any alternative of loader in qml?


Actually some of function of my program stopped when I use asynchronous keyword in loader so is there any alternative of loader or asynchronous in qml?


Solution

  • Here are 3 example for loading component

    //1-loading using loader
    //2-loading component without loader
    //3-loading qml without loader
    
    Window {
        id:appWindow
        width: 300; height: 100; visible: true
    
        property Component cmpontnt:Rectangle{
            width: 10
            height: 20
            color: "red"
        }
    
        Loader{
            sourceComponent:    cmpontnt//1-- loading through loader
        }
    
        Component.onCompleted:{
    
            //2-- loading component using createObject
            cmpontnt.createObject(appWindow, {x: 50, y: 50});
    
    
            //3--creating component from .qml and loading using createObject
            var component2 = Qt.createComponent("TestCmp.qml");
            component2.createObject(appWindow, {x: 80, y: 50});
        }
    
    
    
    }