Results 1 to 20 of 21

Thread: SelectAll causes freeze

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default SelectAll causes freeze

    Greetings.

    I've described the main functionality of my intended application several times, but let me reiterate.

    I receive data really fast from a worker thread, which i add to my model, and i update the view on every tenth packet received, with beginInsertRows/endInsertRows. I use a treeview (mainly because of the usefulness of uniformRowHeights, since at this moment, there are no child items, only top level items).
    I added a popupmenu to be shown when i right click inside the view, and i have a select all command, for which i call selectAll() on the view.

    At this point, the application freezes. This doesnt happen, when all the data is already received, i.e. when no more rows are inserted. I even tried disabling updates, blocking signals from the model, and such unorthodox practices, but it does not work.

    Any ideas?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SelectAll causes freeze

    Probably this behavior appears when you call selectAll while the model data is being changed.
    Try queuing the data when the menu becomes visible. You will not update the view every ten packets, instead you put them in a list and refresh the view when the popup closes.

    But I don't know if it works.

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

    Default Re: SelectAll causes freeze

    Yes, i'm aware that that is the probable cause. Which i tried to eliminate by blocking signals from the model before i call the selectAll() method and unblock them right afterwards.
    Even if this isn't the correct way to do it, the way i understand it, it should work, or at least it should eliminate the probability that the model inserts are causing this.
    Am i wrong?

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SelectAll causes freeze

    How do you exactly receive the data from the worker thread?

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

    Default Re: SelectAll causes freeze

    As objects which contain the data for an entire row in the view, through the signals and slots mechanism, the fastest way i can right now, 1000 every second.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SelectAll causes freeze

    It might be because the view does not refresh as fast as the model.
    Since selectAll has an impact on the view too, and it queries the model directly for the items, you could obtain unpredictable behavior.

    For example if you have 1000 items in the model and the view updates so it too contains 1000 items, and in the very next moment you add another 1000 items to the model, and call selectAll(before the view gets updated) then selectAll will try to update 2000 items in the view. Therefore the behavior.

    But this is just an assumption.
    What you can do is to queue model updating until selectAll end.

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

    Default Re: SelectAll causes freeze

    Let me see if i understood you correctly. So you are saying that i should take the following course, when selectAll is pressed:
    1) set a flag, which will have the effect of the newly arrived data to be directed into a queue, instead of being added directly to the model data
    2) call selectAll() on the view
    3) clear the flag
    4) add all items saved up in the queue to the model data.

    And this all happens, because between the call of selectAll and the actual updating of the view, the model most certainly changes, since it gets data really fast?

    I have to tell you, i didnt think it will be an issue, since somewhere down the path, selectAll uses a list a model indices which have to be set to selected and which are available at that exact moment. Now, it may happen that by the time the view updating occurs, there are many more actual items in the model, and thus, more indices, but there are never less, and i dont see how the originally selected indices could become invalid.
    What is my misconception about all of this?

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SelectAll causes freeze

    I have to tell you, i didnt think it will be an issue, since somewhere down the path, selectAll uses a list a model indices which have to be set to selected and which are available at that exact moment. Now, it may happen that by the time the view updating occurs, there are many more actual items in the model, and thus, more indices, but there are never less, and i dont see how the originally selected indices could become invalid.
    What is my misconception about all of this?
    First of all, all I said is just a guess. It is pretty hard to state some facts.
    Second of all, you misunderstood me.
    I was trying to say that it is possible to have a discrepancy between the number of indexes in the model and the number of items actually painted in the view.

    When you call selectAll, it will try to select N items in the view, while the view contains only M items, where N >= M.

    So, this could even be a stupid idea, but it would be great if you could do some debug to see if it is true, or even implement it, it's not a big deal.

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

    Default Re: SelectAll causes freeze

    Sorry for the misunderstanding.

    When i said "I have to tell you", i didn't mean to sound condescending or preachy, or anything, it just means, that it really didn't occur to me. This expression is an unfortunate american mannerism that i picked up.

    I understand you now, i hope and i believe you are right.
    I modified the code so that for every new item, a beginInsertRows/endInsertRows method is called, not just for every tenth.
    The select all now works, and i think its what you said, because whenever i update the view for only every tenth item, it may happen that the model contains up to 9 items more than the view actually shows.

    Nevertheless, i need this item "buffering" for speed reasons. What can i do to keep this kind of buffering and also to be able to use selectAll? The two issues seem irreconciliable.

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SelectAll causes freeze

    Nevertheless, i need this item "buffering" for speed reasons. What can i do to keep this kind of buffering and also to be able to use selectAll? The two issues seem irreconciliable.
    What about buffering the row data in the GUI thread? From the point selectAll starts, everything that comes from the worker thread goes to a temporary buffer. After select all ends, emit a signal and in the slot just update the model with the items in the temp buffer.

  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

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

  12. #12
    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 )

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.