[Solved] Sorting QML Tableview is slow

we have implemented a sortable table in QML. Sorting takes a long time, I haven't measured exactly, but it is approximately a minute for about 8000 rows. I've ran the test through a profiler and according to that, within the QSortFilterProxyModel::sort() function, most of the time (>99%) is spent in QAbstractItemModel::LayoutChanged() and subsequent calls. We emit the layoutChanged() only after sorting has completed. So this is puzzling me quite a bit. So my question is: Is this signal emitted internally during the sort function? If yes, are these sort times normal for a QML table?

I am pretty sure the QSortFilterProxy tries to move the items in the model so that they can be animated. I think you might be better off with just resetting the entire model if you have a lot of items. I will say that you would think it wouldn't need to move items outside of the view, but idk how qml implements a tableview. You would call QAbstractItemModel::modelReset(). I guess you could try to slap it into a C++ table view and see if the same behavior is observed.

I think Buttink is right. I suggest to add a boolean property to your model in C++ that is true only during sorting. Then you could use this property to detach the model from the view during sorting in QML like this: