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. [Solved] Sorting QML Tableview is slow
Forum Updated to NodeBB v4.3 + New Features

[Solved] Sorting QML Tableview is slow

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqtableviewqsortfilterprox
8 Posts 5 Posters 4.8k Views 2 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.
  • E Offline
    E Offline
    eagain
    wrote on 9 Mar 2015, 15:12 last edited by JKSH 3 Oct 2015, 12:57
    #1

    Hello folks,

    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?

    void MySortFilterProxyModel::setSortOrder(Qt::SortOrder order)
    {
    	QAbstractItemModel* src = qobject_cast<QAbstractItemModel*>(source());
    	emit src->layoutAboutToBeChanged();
    
    	QSortFilterProxyModel::sort(0, order);
    
    	emit src->layoutChanged();
    }
    

    I read various threads and questions on the topic, but none of them seems to match our setup with using a QML tableview and they usually somewhere emit the layoutChanged() which makes them slow.

    On demand I could post complete sources but I do not think they are at fault here.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eagain
      wrote on 9 Mar 2015, 16:17 last edited by eagain 3 Sept 2015, 17:01
      #2

      Results of profiling after sort() to show that none of our custom functions is involved..I've inspected the all of the tree and there is no more of our code involved, only Qt internals.

      99,78 QSortFilterProxyModel::sort
      99,78 ----QSortFilterProxyModelPrivate::sort
      99,78 --------QAbstractItemModel::layoutChanged
      99,78 ------------QMetaObject::activate
      99,78 ----------------QMetaObject::activate
      99,78 --------------------QMetaObject::metacall
      99,78 ------------------------QQmlDelegateModel::qt_metacall
      99,78 -----------------------------QQmlDelegateModel::qt_static_metacall
      99,78 ---------------------------------QQmlDelegateModel::_q_layoutChanged
      99,7 ---------------------------------------QQmlDelegateModel::_q_itemsMoved
      0,01 ---------------------------------------QList<QQmlDelegateModelItem *>::at
      0,01 ---------------------------------------QQmlDelegateModelItem::modelIndex
      0,01 ---------------------------------------QQmlDelegateModelItem::setModelIndex
      0,00 ---------------------------------------QQmlDelegateModelPrivate::itemsMoved
      0,00 ---------------------------------------QPersistentModelIndex::row
      0,00 ---------------------------------------QVectorQQmlListCompositor::Insert::~QVectorQQmlListCompositor::Insert
      0,00 ---------------------------------------@ILT+10530(?setModelIndex@QQmlDelegateModelItem@@QAEXH@Z)
      0,00 ---------------------------------------QQmlListCompositor::listItemsMoved

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Buttink
        wrote on 9 Mar 2015, 17:28 last edited by
        #3

        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.

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on 9 Mar 2015, 22:45 last edited by
          #4

          Hi eagain!

          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:

          MyTableView {
          model: myModel.isSorting ? null : myModel
          }

          Cheers!
          Wieland

          1 Reply Last reply
          1
          • E Offline
            E Offline
            eagain
            wrote on 10 Mar 2015, 09:41 last edited by eagain 3 Oct 2015, 09:49
            #5

            Wow, nice! That did indeed help. Works like a charm now. Cleaned it up a little while I was editing, turns out you don't need to emit layoutChanged at all.

            P 1 Reply Last reply 10 Mar 2015, 11:06
            0
            • E eagain
              10 Mar 2015, 09:41

              Wow, nice! That did indeed help. Works like a charm now. Cleaned it up a little while I was editing, turns out you don't need to emit layoutChanged at all.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 10 Mar 2015, 11:06 last edited by
              #6

              @eagain you can use the "Mark Solved" in "Topic Tools" box to mark topic as solved ;)

              157

              E 1 Reply Last reply 10 Mar 2015, 12:24
              0
              • P p3c0
                10 Mar 2015, 11:06

                @eagain you can use the "Mark Solved" in "Topic Tools" box to mark topic as solved ;)

                E Offline
                E Offline
                eagain
                wrote on 10 Mar 2015, 12:24 last edited by
                #7

                @p3c0 I tried, but apparently im too blind to find that button. The "Topic Tools" only contain the option to "Delete Topic"

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JKSH
                  Moderators
                  wrote on 10 Mar 2015, 12:57 last edited by JKSH 3 Oct 2015, 12:58
                  #8

                  @eagain said:

                  @p3c0 I tried, but apparently im too blind to find that button. The "Topic Tools" only contain the option to "Delete Topic"

                  At the moment, only moderators can mark topics as solved: http://forum.qt.io/topic/51926/real-quick-forum-things/4 Tero, our community manager, is looking to give every user that ability.

                  In the meantime, I believe you can mark it by editing the original post and adding "[Solved]" to the start of the title.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0

                  1/8

                  9 Mar 2015, 15:12

                  • Login

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