How to pass a big list of coordinates to qml and move item over those coordinates?
-
Hi All :)
I'm working on a QtQuick application part of which I'm not sure how to implement.
The part is as follows: on C++ side I'm generating a list containing pairs of qreals (x,y coordinates). The list can be of a considerable length ~10000. Once the list is generated I need to somehow pass this list to QML to move some item (like a ball) around in accordance to the coordinates in this list. I can certainly have it passed using some Q_INVOKABLE but that doesn't sound like a good solution from performance stand point. Also I thought that instead of passing the list I could provide a Q_INVOKABLE which would return single coordinate at particular position, but this seems to be even worse.
Having a model for this would be great but I don't see how it can be implemented.I would appreciate any suggestions, ideas or opinions.
Thanks.
-
You could have a timer running in the background, eg. every 20ms, and in the timeout move the item to the next position and remove the old position. I'd recommend QQueue to manage positions and QTimer to run the timer.
Pseudocode:
QQueue points; QTimer tmr; connect(tmr, QTimer::timeout, this, MyClassName::myTimeoutSlot) void MyClassName::myTimeoutSlot() { toMove.move(points.dequeue()) }
-
@diredko Why passing it once using a normal function (Q_INVOKABLE) would hurt performance in your opinion? It would certainly be more efficient to have a big list in QML than use a function again and again, and such a list isn't big for modern hardware (couple of hundreds of KBytes maybe). If you can afford to have that list in C++ you should be able to afford to have it in QML, too.
I think the biggest performance obstacle is that the system isn't real-time, QML may do garbage collection and animation isn't fluent. I recommend just testing with the most easy solution in the lowest end hardware it will be run on and deciding after that if it's enough.
2/3