Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QListView only load visible items?
Forum Updated to NodeBB v4.3 + New Features

QListView only load visible items?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 4.1k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    toffermann
    wrote on last edited by
    #1

    Hello everyone,

    I have a questions regarding listviews in QT 5 without QML.

    I have a iterator based C API that contains about 5000 items. Now I want to display them inside a QListView.
    I introduced a class inheriting the QAbstractListModel as the delegate and added the model to the view.

    The first thing I do not really understand is, why all items are loaded after I add the model to the listview. In terms of performance it would preferable to only load the visible items. After initially the data function is called ~5000 times further scrolling through the list only updates the surrounding rows (as expected)

    Are all rows in memory after adding the model to the view?

    I also tried the fetchMore and canFetchMore approach, but then I do not know the total count of rows at the beginning and the scrollbar is not correct.

    Greetings tore

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      How did you determine that all items are loaded when you add the model?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toffermann
        wrote on last edited by
        #3

        I added debug messages to the data function.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          I'm not seeing this behaviour on my implementation. Are you sure the data function calls are the result of the ListView?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toffermann
            wrote on last edited by
            #5

            What does your rowCount function return?
            If it returns 5000, the data function gets called 5000 times for me.

            I actually don't do anything more with the model than adding it to the view (view->setModel( model ).

            Am I missing anything else?

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Hi,
              What is the problem? Maybe the View just checks if all data elements are there and available so it doesn't crash when it doesn't get proper data before it starts showing information. Maybe you call the data function yourself?
              When the view only calls data when scrolling it is working great and gives great performance by only updating the data in view.
              Do you call the reset signal? How do you fill the model with data?

              Greetz, Jeroen

              1 Reply Last reply
              0
              • T Offline
                T Offline
                toffermann
                wrote on last edited by
                #7

                Hello again,

                aehm the problem is, that I would like to know how the view actually retrieves the data from the model.

                On a development PC it is no problem to have a list with about 5k items loaded at the beginning, but if the list gets bigger and the applications runs on an embedded device I want to save as much resources as possible.

                What I want the view to do is simply:

                1. Call rowCount -> return 5k entries.
                2. Adapt the scrollbar to fit 5k entries
                3. Only load entries 1-20, because those are actually visible inside the view.

                Greetings

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  t3685
                  wrote on last edited by
                  #8

                  In that case you can either use the debugger to follow function calls or look at QListView code to see what is happening.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    arsinte_andrei
                    wrote on last edited by
                    #9

                    sorry for my ignorance but i did not get few things... how do you populate the model? what model it is? QTableModel, qSqlQueryModel... and so on.. what database are you using ?from where are you taking the data 5000 rows MySql, SQLite, ...All this info are useful in order to give a proper answer to your problem

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      toffermann
                      wrote on last edited by
                      #10

                      I simply use the setModel method

                      @AppQtServiceListModel model = new AppQtServiceListModel();
                      ui->list_view->setModel( model );@

                      The AppQtServiceListModel is based on a QAbstractListModel.

                      After creating the model instance I call an external API function to set the totalCount. -> rowCount now returns the already mentioned ~5k entries.

                      Now the data function gets called:

                      @QVariant AppQtServiceListModel::data( const QModelIndex &index, int role ) const
                      {
                      if ( ! index.isValid() )
                      return QVariant();

                      if ( index.row() >= servicesTotal || index.row() < 0 )
                      return QVariant();

                      if ( role == Qt::DisplayRole )
                      {
                      qDebug() << "index row " << index.row();

                      /* Set the cursor of the external API to match the row index */
                      ListSetCursorIndex( list, index.row() );
                      ...
                      return a QVariant with the desired value...
                      }
                      

                      }
                      return QVariant();
                      }@

                      Thats basically all.

                      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