Creating a lot of the same qml components
-
Hey,
I got a question I create a lot of qml components and since there can be even 100 of this objects it takes a lot of time on android devices(even up to 3-4 sec, if the device is slower). All of them are the same objects(same .qml file) with diffrent parameters, is there any better way then just create it? Is it possible to create one empty object(without parameters set) and copy it somehow, I was looking for method to copy QObject but as far as I know its not possible?
Is there any better way to do it?
Thanks in advance
-
Hi,
Well I'm not aware of any such way but are you creating all the 100 Items at same time Or do you need to show all of them at the same time ?
-
Loading all items at once will always take some time. Better way would be to load them as and when required and then if they are frequently used keep them loaded.
-
100 or more items for sure does not fit inside the screen together, so you should avoid to load all at once the Item delegated to visualize that information on the screen.
Qt Quick come in your help with ListView, GridView and TableView. Each of them take a Model (ListModel, or something else) that contains only the data (i.e. the parameters of each item) and usually it's just one object very fast to load even if there is a list of thousands of elements, and then you define a delegate Item that it's your Qt Quick component that takes the parameters and visualize them on the screen.
ListView (& co.) loads only the Items necessary to get displayed on the screen and in this way there will be only few loading/creation of objects.