【问题标题】:Difference between QML's Component and Instantiator?QML 的 Component 和 Instantiator 的区别?
【发布时间】:2016-08-07 23:10:42
【问题描述】:

QML 类型 ComponentInstantiator 似乎做了类似的事情;按需创建 QML 对象,而不是在解析其定义时。 那么有什么区别?我为什么要使用一个而不是另一个?

【问题讨论】:

    标签: qt qml qtquick2 qt-quick qqmlcomponent


    【解决方案1】:

    Instantiator 创建给定 Component 的实例 - 为model 中给出的每个模型条目创建一个实例。它类似于中继器。

    Component 是一个类。 Instantiator 是给定组件的工厂。

    【讨论】:

    • 但是我不能在没有Instantiator 的情况下创建Component 的实例吗?
    • 有多种可能性,选择最适合您的一种:您可以将Loader 用于单个实例,Repeater'](http://doc.qt.io/qt-4.8/qml-repeater.html) for multiple instances. Since QtQml2.2 there is also the [Instantiator' 是可以异步加载的中继器。您还可以使用 Component.createrObject()Component.incubateObject() 附加到每个 Item
    • 你可以把Component想象成对象的原型。就像C++ 中的class MyClass{}Instantiator 是一个创建项目的真实对象。所以这些项目的父级是Instantiator。当您创建Componentinstance 时,您应该设置一个父级。
    猜你喜欢
    • 2019-09-23
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2021-03-10
    相关资源
    最近更新 更多