Important: Please read the Qt Code of Conduct -

[SOLVED] Qt model alternative?

  • Hi,

    I'm old Delphi/FreePascal/Lazarus programmer. I'm programming in Qt and C++ from a year. The most painfull for me in Qt is model programming. Especially efficient. For example filling QStandardItemModel with 1 million records take ~15 seconds, 700MB memory usage and QTreeView scrolling is almost impossible (100% CPU, seems that each scroll validate even not visible items). For comparison, in Lazarus I have TVirtualTreeView where I override one virtual method OnGetData. In arguments I get row and column index and returning data from TList (something like QList) or from dynamic array. Result: filling 1 million records = 150 ms, +20MB in RAM, fully responsible scrolling (OnGetData is called only for visible items). I tried also with QAbstractItemModel, a lot of coding and I only reduced memory usage (not so much).
    My question: Is there any alternative for model programming? Few months ago I saw tutorial for custom dataset in QTreeView but can't find it now. They used simple QList and override few methods in QTreeView.


  • Ok I rewrote my model carefully while reading QAbstractItemModel documentation. I reduced memory usage a lot but still had lags while scrolling 1 million records. I changed QTreeView to QListView / QTableView and everything worked very fast. So I checked QTreeView properties and disabled itemsExpandable and checked uniformRowHeights. Finally my view is fast and furious :) . Loading 1 mln record = 1 second, +140MB in RAM, smooth scrolling without lags. Thanks!

  • Lifetime Qt Champion

    Nice improvements !

    Can you share the technique used model side ? :)

Log in to reply