【问题标题】:QML: How to set dynamically created component to the LoaderQML:如何将动态创建的组件设置为加载器
【发布时间】:2011-11-02 09:59:16
【问题描述】:

我正在使用以下代码创建新的 QML 屏幕。

var newComp = Qt.createComponent(“test.qml”);
var newObject = newComp.createObject(parent, {“x”: 0, “y”: 0});

我想将此组件设置为加载程序。

我已经尝试过使用Loader.sourceComponent = newObject;

它有效,但它给了我以下错误。

“Error: Cannot assign QObject* to QDeclarativeComponent*”

是否有任何解决方法。

谢谢。

【问题讨论】:

    标签: qt qml qt-quick


    【解决方案1】:

    Loader.sourceComponent 必须是一个组件,所以

    Loader.sourceComponent = newComp 
    

    应该可以。

    但这和

    Loader {
        source: "test.qml"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多