Results 1 to 3 of 3

Thread: Updating QListView from a thread

  1. #1
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Windows

    Default Updating QListView from a thread

    Hi Everyone

    I have a QListView descendant which is updated when messages come in to our application over our network. A customer has an issue whereby at times when the network traffic is excessively high the CPU time sky rockets and our main application is unable to process messages ie the UI fails to respond. This is the very time they need to use the UI but are unable to until the messages stop.

    My solution works well, this was to defer the messages onto a list, have the list monitored by a Win32 Thread, and when the message count is > 0 fire off an event from the thread that causes the event handler to update the QListView within the context of the monitoring thread but allowing that thread to sleep between message updates. All handling of data is done within a critical section as is the actual call to update the QListView.

    As I say this works great however I have since read in the QT Assistant and in a QT white paper on multithreading that "While writing thread-enabled GUI applications with Qt, all GUI-related operations must be performed in the main thread only". My solution has performed beautifully through intensive testing but we are now consequently concerned that we are doing something that the documentation tells us not to do!

    Does anybody have any comments on this or is there another way I can achieve my goal of updating the QListView under intense network traffic without locking the UI? This is a Win32 application running on XP.

    Thanks in advance.

    Paul

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Updating QListView from a thread

    I guess the problem occurs when inserting new items in the model?
    If so, you need to know that inserting an item is very costly. Try using the fetchMore and canFetchMore functions of the model.

    Edit: or qApp->processEvents(); will help too.

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

    Paul1892 (9th July 2010)

  4. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Updating QListView from a thread

    Quote Originally Posted by tbscope View Post
    qApp->processEvents(); will help too.
    That one is tricky as it may mess up your event loop.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 5
    Last Post: 12th October 2009, 10:05
  2. Replies: 16
    Last Post: 7th October 2009, 08:17
  3. Updating directory view in a QListView
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2009, 23:48
  4. QListView not updating
    By Terabyte in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2009, 07:10
  5. Problem updating Line edit from a thread
    By raghvendramisra in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 05:05

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.