qml 中是否有加载器的替代品?

问题描述

实际上,当我在 loader 中使用 asynchronous 关键字时,我的程序的某些功能停止了,那么在 qml 中是否有 loader 或 asynchronous 的替代方案?

解决方法

这里有 3 个加载组件的例子

//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});
    }



}