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.
相关问题
- QML: Cannot read property 'xxx' of undefin
- QML: Cannot read property 'xxx' of undefin
- QTextEdit.find() doesn't work in Python
- QT Layouts, how to make widgets in horizontal layo
- QT GUI freezes even though Im running in separate
相关文章
- ubuntu20.4中c#通过c++库调用python脚本
- Qt槽函数自动执行多遍
- Is there a non-java, cross platform way to launch
- How to get a settings storage path in a cross-plat
- Why doesn't valgrind detect a memory leak in m
- QTreeView remove decoration/expand button for all
- qt界面拥挤
- how do I correctly return values from pyqt to Java
I find that the Dynamic QML Object Creation from JavaScript page can be misleading.
There's no mention about using a declaratively created
Component
or using models instead. It mentions onlyQt.createComponent
orQt.createQmlObject
which are needlessly imperative (and relying on strings) most of the time.I would advise using an inline
Component
withcreateObject()
instead for more readable and maintainable code. Like so :I'd use this method if I wanted to create a temporary object imperatively, like a popup for example.
If I were to create several of those objects, I'd most likely use a
ListModel
with aListView
/Repeater
/Instantiator
/... like so:Here I don't even have to handle the the object creation, I just insert some data in the
ListModel
and theRepeater
takes care of the instantiation of the delegates.You can use a
Repeater
to create components withoutLoader
. Or you can even useQt.createComponent
to do that.Take a look at Qt Documentation about Dynamic Component Creation in QML
information and examples about
Repeater
can be found hereYou can even create component from string on the fly: