【问题标题】:QML: object instantiationQML:对象实例化
【发布时间】:2018-05-09 22:58:05
【问题描述】:

有没有一种类似于Component.createObject's 第二个参数(初始属性)和Loader 元素的机制?我在onLoaded 中手动设置属性,但这在语义上略有不同。

【问题讨论】:

    标签: qt qml qt5 object-construction


    【解决方案1】:

    使用setSource():

    // example.qml
    import QtQuick 2.0
    Item {
        Loader {
            id: squareLoader
            onLoaded: console.log(squareLoader.item.width);
            // prints [10], not [30]
        }
    
        Component.onCompleted: {
            squareLoader.setSource("ExampleComponent.qml",
                                 { "color": "blue" });
            // will trigger the onLoaded code when complete.
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多