+ Reply to Thread
Results 1 to 4 of 4

Thread: Updating QStandardItemModel model which is set to view takes long time

  1. #1
    Join Date
    Dec 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Updating QStandardItemModel model which is set to view takes long time

    Hello,

    I currently have two grids, one at the top and one at the bottom.
    I have fifty rows in the bottom grid, and 'n' rows in the top grid.
    On clicking "Add rows" button, I need to add the 50 rows in the bottom grid to the top grid, and color the newly added rows.
    Then, I need to remove all rows in the bottom grid.

    I am using QStandardItemModel as the source model for the two grids.

    I tried using "insertrow" from the qstandarditemmodel, to pass qstandarditem values obtained from the second grid, to the function.
    It still takes about one second, for as less as 50 rows to update an existing model with new rows.

    Is there a way to do this quickly?

    Thanks,
    Padma

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,874
    Thanks
    3
    Thanked 449 Times in 432 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QStandardItemModel model which is set to view takes long time

    How are you moving the item between the models ?

    Are you just removing and inserting the rows ?

    or

    using takeItem() and insertItem() ? This is relatively faster than other method.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Dec 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Updating QStandardItemModel model which is set to view takes long time

    I modified the code based on your recommendation:

    I used 'takeItem' and added the QStandardItem to a list with row items.
    Then I take this list and use 'InsertRow' to insert it into the top grid.
    I couldnt find 'insertItem' for qstandarditemmodel.. I found that 'setItem' takes way too much time, when editing a model that has already been set to the view..

    It is now at about 0.86, slightly better.

    I am still not sure as to why it would take as much time, when loading 100+ rows initially into the grid is almost instantaneous..

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,874
    Thanks
    3
    Thanked 449 Times in 432 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QStandardItemModel model which is set to view takes long time

    QStandardItemModel and QStandardItem are out of box solutions for table view, which may not give efficient results with large data sets, as internally QStandardItemModel needs to many house keeping stuff, which may be a overhead and may not be required for your application.

    If performance and response is important for your application then better implement a custom model, which will be a bit complicated than using StandardItemModel but it all depends on your application data model.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

+ Reply to Thread

Similar Threads

  1. Replies: 24
    Last Post: 18th September 2013, 06:35
  2. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 10:29
  3. Problem: the Application Takes very long time to build
    By Ma7moud El-Naggar in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2010, 06:26
  4. Replies: 2
    Last Post: 5th October 2010, 08:20
  5. QImage::scaled takes long time
    By nrabara in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 12:19

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