无需加载器即可实例化内联组件 [英] Instantiate inline Component without Loader
本文介绍了无需加载器即可实例化内联组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种不使用 Loader
来实例化内联 Component
(即在同一个文件中定义)的方法?我不太关心使用 Loader
的性能影响,因为我担心使用大量 Loader
包装器污染我的文件.
Is there a way of instantiating an inline Component
(i.e. defined in the same file) without using a Loader
? I'm less concerned about the performance impact of using Loader
s as I am about polluting my file with lots of Loader
wrappers.
推荐答案
您可以使用 Repeater
来创建没有 Loader
的组件.或者你甚至可以使用 Qt.createComponent
来做到这一点.
You can use a Repeater
to create components without Loader
.
Or you can even use Qt.createComponent
to do that.
查看 Qt 文档关于QML 中的动态组件创建
关于Repeater
的信息和例子可以在这里
information and examples about Repeater
can be found here
您甚至可以动态地从字符串创建组件:
You can even create component from string on the fly:
Rectangle {
id: appWindow
width: 300; height: 300
Component.onCompleted: {
var newObject = Qt.createQmlObject('import QtQuick 2.0; Rectangle {color: "red"; width: 20; height: 20}',
appWindow,
"dynamicSnippet1");
}
}
这篇关于无需加载器即可实例化内联组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文