Results 1 to 4 of 4

Thread: Slow performance: Removing huge amount of rows from qstandarditemmodel

  1. #1
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Slow performance: Removing huge amount of rows from qstandarditemmodel

    I have a QStandardItemModel with 10000 Rows. If I want to remove a huge percent of these like 5000 the performance is very bad and the gui freezes. I could run the remove in a thread, but I am concerned what could happend if a user clicks a row that is going to be removed shortly.

    Qt Code:
    1. QModelIndexList indexes = ui->playTableView->selectionModel()->selectedRows();
    2.  
    3. for (int i=0; i<indexes.count(); i++) {
    4. if (!ui->playTableView->isRowHidden(indexes[i].row()) ) {
    5. plmodel->removeRow(indexes[i].row());
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    This works, but takes very long time; maybe 30 seconds. it gives a bad user experience. Is there a faster way?

    any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slow performance: Removing huge amount of rows from qstandarditemmodel

    Each removeRow() will result in two signals to update any view using the model.

    One possible improvement would be to find ranges of rows that can be removed with removeRows().

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    gig-raf (30th March 2016)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Slow performance: Removing huge amount of rows from qstandarditemmodel

    Before you worry about performance you should consider correctness. What happens if you have a five row model containing A..E, all selected? Your cached selection lists rows 0..4 in that order (this order is not guaranteed anywhere IIRC). Your loop deletes row 0(A)leaving the original rows 1..4 (B..E)as rows 0..3. You then delete row 1, which is the original row 2 leaving the model containing B, D, E. You then delete row 2, leaving B, D, and then proceed to try deleting row 3 and 4. You need to delete in reversed row order to avoid this.

    Every time you remove a row from the model the remaining 4000+ model indexes in the selection model must be updated because removing a row will change the row number of any index pointing to a later row. It is likely that clearing the selection model after caching the selected indexes but before doing the deletes will help.

  5. The following user says thank you to ChrisW67 for this useful post:

    gig-raf (30th March 2016)

  6. #4
    Join Date
    Jun 2012
    Posts
    38
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Slow performance: Removing huge amount of rows from qstandarditemmodel

    First of all thanks for taking the time to answer me.

    @chrisW67: Yes true, the logic was wrong, even correcting it deleting row by row is very slow.

    @anda_skoa: I manage to speed things up using the removeRows(), thanks for the idea.

Similar Threads

  1. Replies: 34
    Last Post: 22nd March 2016, 17:34
  2. Replies: 8
    Last Post: 17th February 2014, 03:36
  3. Replies: 4
    Last Post: 5th May 2010, 13:24
  4. Replies: 3
    Last Post: 1st February 2008, 18:18
  5. Huge tableview low performance
    By semoser in forum Qt Programming
    Replies: 9
    Last Post: 9th November 2006, 17:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.