Results 1 to 17 of 17

Thread: QTableWidget Update - slow

Threaded View

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

    Default Re: QTableWidget Update - slow

    Quote Originally Posted by jacek
    You don't invoke beginInsertRows() and endInsertRow() in MyGameModel::insertRow().
    This shouldn't influence the speed so much.

    My guess is, apart from anything else, that the other thread may be starving the model. Is this other thread really necessary? Or maybe you could add data by blocks and not one by one? Hundred messages per second need to be inserted into the queue and retrieved from it and processed, that's much work. Maybe you could use something like this:

    Qt Code:
    1. QMutex mutex;
    2. QList<TabbedDataParser*> sharedlist;
    3.  
    4. // "worker" thread:
    5. mutex.lock();
    6. bool needSignal = sharedlist.isEmpty();
    7. sharedlist << new TabbedDataParser(...);
    8. if(needSignal) emit newData();
    9. mutex.unlock();
    10.  
    11. // "gui" thread
    12. void GUIThreadClass::slotConnectedToNewData(){
    13. mutex.lock();
    14. while(!sharedlist.isEmpty()){
    15. TabbedDataParser *elem = sharedlist.front();
    16. sharedlist.pop_front();
    17. processData(elem);
    18. }
    19. mutex.unlock();
    20. }
    To copy to clipboard, switch view to plain text mode 

    You can still improve it. The code I wrote blocks the worker thread while the main thread processes data. You can make it that the list is only locked by the main thread when it actually retrieves data from it and when it processes the data, the other thread could still insert new items. Something like this could work:
    Qt Code:
    1. void GUIThreadClass::slotConnectedToNewData(){
    2. forever{
    3. mutex.lock();
    4. if(sharedlist.isEmpty()){
    5. mutex.unlock(); break;
    6. }
    7. TabbedDataParser *elem = sharedlist.front();
    8. sharedlist.pop_front();
    9. mutex.unlock();
    10. processData(elem);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    This way instead of emitting 200 signals (which end up in the event queue), you emit one or two.
    Last edited by wysota; 17th August 2006 at 21:51.

  2. The following user says thank you to wysota for this useful post:

    DPinLV (17th August 2006)

Similar Threads

  1. Replies: 5
    Last Post: 27th May 2006, 13:44
  2. Replies: 6
    Last Post: 5th March 2006, 21:05
  3. Updating a QTableWidget through a Dialog
    By dragon in forum Newbie
    Replies: 3
    Last Post: 19th January 2006, 21:16
  4. Update a row
    By dragon in forum Newbie
    Replies: 9
    Last Post: 17th January 2006, 17:11
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.