Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to pass a big list of coordinates to qml and move item over those coordinates?

How to pass a big list of coordinates to qml and move item over those coordinates?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqtquickc++listinvokable
3 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    diredko
    wrote on 10 Jun 2017, 08:06 last edited by
    #1

    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.

    E 1 Reply Last reply 10 Jun 2017, 15:18
    0
    • A Offline
      A Offline
      ArsenArsen
      wrote on 10 Jun 2017, 08:33 last edited by
      #2

      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())
      }
      
      1 Reply Last reply
      0
      • D diredko
        10 Jun 2017, 08:06

        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.

        E Offline
        E Offline
        Eeli K
        wrote on 10 Jun 2017, 15:18 last edited by
        #3

        @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.

        1 Reply Last reply
        0

        2/3

        10 Jun 2017, 08:33

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved