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. Model for a list of large data in QML
QtWS25 Last Chance

Model for a list of large data in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
21 Posts 5 Posters 7.1k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #10

    My - perhaps crazy - thought: use the QSql model to read your DB (side note: perhaps some other db would work better, like psql or mariadb. SQLite tends to be rather slower than others), preferably in a separate thread. When DB data changes, emit a signal to notify the upper layers. Then set up another model, like QAbstractListModel or model proxy which will:

    • remember which list elements were expanded/ collapsed (btw. to display these list items, I'd recommend implementing some custom QML delegate). You can simply extend the data object you get from SQL model and add a boolean variable to mark which items were expanded
    • present the "last read" info from your DB. So, while your SQL model will be busy reading new data (after some background data change), your proxy model will still hold and display old data. Once all is read, it will get the signal from SQL model and update itself

    (Z(:^

    JonBJ 1 Reply Last reply
    2
    • sierdzioS sierdzio

      My - perhaps crazy - thought: use the QSql model to read your DB (side note: perhaps some other db would work better, like psql or mariadb. SQLite tends to be rather slower than others), preferably in a separate thread. When DB data changes, emit a signal to notify the upper layers. Then set up another model, like QAbstractListModel or model proxy which will:

      • remember which list elements were expanded/ collapsed (btw. to display these list items, I'd recommend implementing some custom QML delegate). You can simply extend the data object you get from SQL model and add a boolean variable to mark which items were expanded
      • present the "last read" info from your DB. So, while your SQL model will be busy reading new data (after some background data change), your proxy model will still hold and display old data. Once all is read, it will get the signal from SQL model and update itself
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #11

      @sierdzio
      This sounds reasonable to me.
      The only thing is: given the OP's "crazy" ( ;-) ) requirement to have "at least 100k" items in his lists, it sounds like the approach will require yet another copy of all the data rows! :(

      sierdzioS X 2 Replies Last reply
      0
      • JonBJ JonB

        @sierdzio
        This sounds reasonable to me.
        The only thing is: given the OP's "crazy" ( ;-) ) requirement to have "at least 100k" items in his lists, it sounds like the approach will require yet another copy of all the data rows! :(

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #12

        @JonB said in Model for a list of large data in QML:

        @sierdzio
        This sounds reasonable to me.
        The only thing is: given the OP's "crazy" ( ;-) ) requirement to have "at least 100k" items in his lists, it sounds like the approach will require yet another copy of all the data rows! :(

        That's why it will be crucial to implement @dheerendra's idea of windowed view. Or at the very least use lazy initialization (canFetchMore() and fetchMore()).

        (Z(:^

        JonBJ 1 Reply Last reply
        0
        • sierdzioS sierdzio

          @JonB said in Model for a list of large data in QML:

          @sierdzio
          This sounds reasonable to me.
          The only thing is: given the OP's "crazy" ( ;-) ) requirement to have "at least 100k" items in his lists, it sounds like the approach will require yet another copy of all the data rows! :(

          That's why it will be crucial to implement @dheerendra's idea of windowed view. Or at the very least use lazy initialization (canFetchMore() and fetchMore()).

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #13

          @sierdzio
          Yes, but independent of whether lazy reading is involved, my comment was that OP will have one ("large") list of rows in his QSqlQueryModel and another ("large", potentially very similar) list in his new QAbstractListModel. It may be inevitable, but it was just an observation.

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #14

            Oh, right, that's true.

            (Z(:^

            1 Reply Last reply
            0
            • JonBJ JonB

              @XDePedro said in Model for a list of large data in QML:

              I have actually implemented kind of a test app using QSqlQueryModel but when the data changes I call setQuery again...this I think is very slow and the control is re-filled

              Yes, this is a big problem for you to think through. With your data:

              a. Do you only want to re-fetch incrementally this values which have been added?
              b. When you do re-fetch, do you wish all the old, existing rows to still be in the model/view, or do you want those to be removed and only the new stuff now shown?

              so I lost the location where the user was in the list

              This one is a minor point: if necessary, note the position in the list (via something unique in the data, e.g. a primary key) and restore after re-populate.

              X Offline
              X Offline
              XDePedro
              wrote on last edited by
              #15

              @JonB
              It might be a minor problem but I am still trying to solve it. I have to signals: beginDBChange and endDBChange. I use the first one to store the index of the selected item and then the second one to set it as a current item index. It works but I still have some annoying scrollings to set the item at the beginning or the end of the table. I would like this to be completely transparent to the user.

              JonBJ 1 Reply Last reply
              0
              • JonBJ JonB

                @sierdzio
                This sounds reasonable to me.
                The only thing is: given the OP's "crazy" ( ;-) ) requirement to have "at least 100k" items in his lists, it sounds like the approach will require yet another copy of all the data rows! :(

                X Offline
                X Offline
                XDePedro
                wrote on last edited by
                #16

                @JonB

                Sounds crazy :P but I think I'll give it a try.

                Does someone know if the QSqlQuery use any kind of lazy initialization? or when you execute a query the data is being loaded regardless nobody ask for it??

                sierdzioS 1 Reply Last reply
                0
                • X XDePedro

                  @JonB
                  It might be a minor problem but I am still trying to solve it. I have to signals: beginDBChange and endDBChange. I use the first one to store the index of the selected item and then the second one to set it as a current item index. It works but I still have some annoying scrollings to set the item at the beginning or the end of the table. I would like this to be completely transparent to the user.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #17

                  @XDePedro
                  Not an area I know about; can only make possible suggestion:

                  If you really cannot solve that by (somehow) pre-scrolling before new list is shown --- because list is being completely repopulated from new data --- ISTM you will have to come up with whatever solution to only append new rows to visual list without complete reset/redraw, whatever that might involve.

                  1 Reply Last reply
                  0
                  • X XDePedro

                    @JonB

                    Sounds crazy :P but I think I'll give it a try.

                    Does someone know if the QSqlQuery use any kind of lazy initialization? or when you execute a query the data is being loaded regardless nobody ask for it??

                    sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #18

                    @XDePedro said in Model for a list of large data in QML:

                    Does someone know if the QSqlQuery use any kind of lazy initialization?

                    Like all Q*Model classes, there is canFetchMore() and fetchMore().

                    Whether any further laziness is implemented in the actual loading - I don't know.

                    (Z(:^

                    JonBJ 1 Reply Last reply
                    0
                    • sierdzioS sierdzio

                      @XDePedro said in Model for a list of large data in QML:

                      Does someone know if the QSqlQuery use any kind of lazy initialization?

                      Like all Q*Model classes, there is canFetchMore() and fetchMore().

                      Whether any further laziness is implemented in the actual loading - I don't know.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #19

                      @sierdzio
                      I have been wondering about just this for QSqlQueryModel etc. for a while now!

                      Do we know how the "fetchMore" is actually implemented? I presume this is a driver implementation (QMYSQL)? For example, does it actually use a SQL CURSOR on a still on-going query (I hope not! but maybe it does), does it simply mean it fetches another packet from some complete SQL resultset, or what??

                      This makes a huge difference to how I might implement efficiency in my SQL code....

                      1 Reply Last reply
                      0
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #20

                        Feel free to analyze the code here.

                        (Z(:^

                        JonBJ 1 Reply Last reply
                        2
                        • sierdzioS sierdzio

                          Feel free to analyze the code here.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #21

                          @sierdzio
                          Thanks for that!

                          Unfortunately for me, I do all my work in PyQt. That means I can't step through the code in debugger to follow everything, as I would if I used C++ and had the sources.

                          Although the page's hyperlinks are good, they're not nearly nearly the same as following through stepping.

                          A brief look doesn't tell me much. Though:

                          QSqlQueryModel::fetchMore()
                          Fetches more rows from a database.
                          This only affects databases that don't report back the size of a query
                          (see QSqlDriver::hasFeature()).

                          At a guess MySQL will return "size of a query" (perhaps SQLite does not), so it may be all irrelevant in my situation?

                          In any case, as you'll see I don't think the implementation will be in QSql.... That will rely on the abstraction level of the driver it's using, QMYSQL, and I'm thinking that is where what I would like to know is buried...

                          But thanks anyway.

                          1 Reply Last reply
                          0

                          • Login

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