Results 1 to 5 of 5

Thread: QThread event loop blocking the GUI

  1. #1
    Join Date
    Aug 2007
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QThread event loop blocking the GUI

    Hi,

    I have an app with a big, nicely functioning, GUI that I want to add some threaded processing to, using threads to draw things that take a long time, and since there may be multiple things that take a long time, multi-core systems should draw faster - I hope....

    There are a few (like 3 to 8) of these widgets, each creating their own "DrawingThread" which runs the default event loop. When the widgets draw quickly, everything is fine, but if the drawing thread is taking a long time, the main GUI hangs, timers don't fire, etc. I have added "yieldCurrentThread()" into the worker function in the drawing thread, but that seems to do nothing. Adding msleep( 1000 ) causes the drawing thread to pause for 1 second, but the GUI remains hung during this pause. The worker function is a slot in the DrawingThread object and is fired by a signal emitted by the GUI. In turn, it fires periodic signals to slots (repaint()) in the GUI, and these are being done, but nothing else. So, I see my slow drawing screen slowly work across, while everything else is frozen... Once the drawing is done, everything is snappy again. To be clear, the GUI isn't sluggish, it's dead stopped. Setting the DrawingThread priority down doesn't do anything except cause my app to fall behind others in the system for priority - the GUI still stays hung.

    I've read all about thread affinity, and as far as I can tell, this is it's own thread. I have other threads in the app where I re-implemented the run() and they all work as expected with the GUI continuing nicely while they work, they produce signals but do not consume them. This is my first thread to use the default run() {exec();}, and that seems to be the difference, due to the implementation, these threads need to receive signals....

    It seems like I just have a fundamental implementation issue - any ideas what it might be?

    Thanks,

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread event loop blocking the GUI

    maybe you are waiting for your threads or something?
    Show us some code and we can really help.

  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: QThread event loop blocking the GUI

    You can't render widgets from external threads.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread event loop blocking the GUI

    Wysota is right, of course.
    (You could render to a QImage in a separate thread and then just paint the QImage in the main thread. So the calculations - which should be where the time is consumed - can be done in a separate thread, but the actual painting can not.)

  5. #5
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread event loop blocking the GUI

    QPainter can be used to paint onto QImage, QPrinter, and QPicture paint devices. Painting onto QPixmaps and QWidgets is not supported.
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. QThread event loop seems blocked
    By eurodatar in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2009, 16:50
  2. Replies: 0
    Last Post: 23rd October 2008, 12:43
  3. Qt plug-in for GLib event loop based application
    By profoX in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2008, 14:27
  4. Glib event loop
    By Brandybuck in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2006, 17:19
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

Tags for this Thread

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.