Results 1 to 20 of 21

Thread: SelectAll causes freeze

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    Could we see the code you use for adding data to the model?

  2. #2
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: SelectAll causes freeze

    This is all i use right now to add/modify my model data.
    Qt Code:
    1. if (m_rowNumsForItems.contains(item.ObjectId) == false)
    2. {
    3. /// if the item isn't already in the list, it is added, and the resulting rownum recorded.
    4. if (rowCount() - m_lastUpdatedRow == 10)
    5. {
    6. beginInsertRows(QModelIndex(), m_lastUpdatedRow, rowCount());
    7. }
    8. m_items.push_back(item);
    9. m_rowNumsForItems.insert(item.ObjectId, rowCount() - 1);
    10. if (rowCount() - m_lastUpdatedRow == 11)
    11. {
    12. endInsertRows();
    13. m_lastUpdatedRow = rowCount();
    14. }
    15. }
    16. else
    17. {
    18. /// if the item is in the list, it is replaced and dataChanged is emitted.
    19. rowNum = m_rowNumsForItems.value(item.ObjectId);
    20. m_items.replace(rowNum, item);
    21. emit dataChanged(index(rowNum, 0), index(rowNum, columnCount() - 1));
    22. }
    To copy to clipboard, switch view to plain text mode 

    (The 10 is purely arbitrary, and of course, i need to add some kind of timer, which i dont currently have, so that it doesnt happen that the last <10 items are never shown )

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    And how do you call it?

  4. #4
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: SelectAll causes freeze

    The worker thread emits a signal, with an item as parameter. In the slot connected to it in the main thread i call this addItem function, with the received item as parameter.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    For each single row separately? Why not insert all pending data at once?

  6. #6
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: SelectAll causes freeze

    I don't really understand what you mean by pending. Slot is called with 1 item as parameter, addItem is called in the model with that one item. That is what happens. I tried to lessen the burden on the ui by doing that beginInsertRows/endInsertRows only for every 10 of these items, in bulk, but maybe that was a mistake, because it has the effect that the view has always less items then the model behind it.
    Maybe i should queue the items *always*, in the slot, and add them to the model in bulk?
    Actually taking this buffering outside the model?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    Now I think you are doing something weird... Isn't it true that you do:
    insert row 1
    insert row 2
    ...
    insert row 9
    beginInsertRows
    insert row 10
    endInsertRows

    Instead you should be doing:
    add row 1 to other list
    add row 2 to other list
    ...
    add row 10 to other list
    beginInsertRows
    add all 10 rows from the other list to the model list
    endInsertRows

  8. #8
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: SelectAll causes freeze

    Exactly what im doing now, and exactly the solution which i asked i should do.

    Yes, now that i think of it, it is weird.

    I'll try to do just that + a timer (because it can happen that after a while, the initial surge of data dies down, and maybe i receive 10 new items in 5 minutes, instead of 10ms, so i periodically have to transfer the list to the model list).

    I will try this, hope it works.

    Thanks a lot, Wysota, and you too Marcel, i'm very glad you both are willing to devote time to sort out through my rookie mistakes.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    You can probably use the canFetchMore() and fetchMore() feature of the model to do it without timers.

  10. #10
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: SelectAll causes freeze

    I use the treeview currently as a tableview, i.e. only top level items, no children.
    I've never used canFetchMore() and fetchMore(), could you please explain a bit how it can help?

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SelectAll causes freeze

    The view is irrelevant, it all happens inside the model. canFetchMore() is called to ask whether the model needs to update itself with new rows and fetchMore() does the update.

    In your case canFetchMore() should return true if there are any pending rows and fetchMore() should append them to the model. I don't know if it will work (I never used those two methods), but it's worth to try. At worst you'll have to call those two methods yourself from within the timer.

Similar Threads

  1. QLineEdit selectAll() in eventFilter
    By mclark in forum Qt Programming
    Replies: 6
    Last Post: 1st February 2008, 08:13
  2. QThread , GUI freeze
    By cs_raja in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2006, 10:47
  3. Replies: 4
    Last Post: 10th November 2006, 12:07
  4. QTable Freeze Column
    By sunil.thaha in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 04:21

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.