Results 1 to 6 of 6

Thread: How to refresh GUI while heavy processing is ongoing?

  1. #1
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to refresh GUI while heavy processing is ongoing?

    Hi,

    I'm extracting and processing XML files that causes high CPU occupancy. This causes GUI freezing, so no update is occurring for neither progress bar nor for other elements.

    void NESA::quickProcess()
    {
    qApp->processEvents();
    }


    I've put the following into the constructor:

    timer = new QTimer(this);
    timer->setInterval(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(quickProcess()));

    And before heavy computing I call timer.start();, and when it finishes I call timer.stop();

    However, it is still the same. Any hint? Thanks!


    Added after 16 minutes:


    Does timer start a new thread, is this the reason?
    "Calling this function processes events only for the calling thread."
    Last edited by falconium; 12th May 2011 at 17:51.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to refresh GUI while heavy processing is ongoing?

    If you want the GUI to keep on updating / refreshing, the event loop should continue to loop, while the quickProcess() is running, I think you either need to put quickProcess() in a QThread, or divide quickProcess() into samller blocks and call them in timerEvents();

  3. #3
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to refresh GUI while heavy processing is ongoing?

    Hi Santosh,

    Thanks for the reply!
    I think I was not clear enough. quickProcess() is for processing all the remaining pending events in the loop. There is another, separate function for doing calculations. Do you think putting that into a thread could help?
    Should I call timer.start() inside that thread, or should I use a totally different approach?

    Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to refresh GUI while heavy processing is ongoing?

    During the "heavy computing" no events are processed, so your timer is useless. Either call processEvents() inside your computation or move the hole computation inside a thread or a separate event loop.

    See this article for further informations.

  5. #5
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to refresh GUI while heavy processing is ongoing?

    Thanks Lykurg!
    I have been using processEvents with no user interaction flag inside the computing loop, but it made it very-very slow, so my intention is to call processEvents only occasionally to have a win-win situation. If it is not possible to call a function with timer (as they are also called inside event loop), then I'm going to check the link you included.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to refresh GUI while heavy processing is ongoing?

    Typically I run as little code as possible in the main ui event loop to try and keep it as responsive as possible. Anything that can take >= 250ms per 5 seconds I place into another thread. With signals and slots, Qt makes it really easy to communicate between threads, so all the ui does is react to events and signals.

Similar Threads

  1. Replies: 2
    Last Post: 14th January 2011, 15:09
  2. Painting of lots of computationally heavy pixels
    By Cruz in forum Qt Programming
    Replies: 9
    Last Post: 11th April 2010, 16:35
  3. Replies: 4
    Last Post: 11th December 2008, 17:35
  4. Screen refresh during heavy computation
    By martinb0820 in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2008, 22:20
  5. Application very heavy for lots object
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 29th April 2006, 17:33

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.