Results 1 to 8 of 8

Thread: MainWindow update during computations

  1. #1
    Join Date
    Jul 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default MainWindow update during computations

    Hi all,

    my Qt application is running under Windows XP and I am using a second console window for some output text. Whenever I click on that console window during some computation in the app, the MainWindow is not updated any more (no resize, no redrawing, ...). My whole application is running in a single thread. Is there a way to keep the MainWindow alive during longer computations (including graphical updates).

    I tried QApplication::flush and all kind of update and repaint calls at different places in the code.

    Thanks a lot for any hint!

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: MainWindow update during computations

    You can call QApplication::processEvents() once in a while inside a long lasting loop to make your application responsible.
    J-P Nurmi

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

    aMan (11th July 2006)

  4. #3
    Join Date
    Jul 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MainWindow update during computations

    Perfect. Exactely what I needed, thx.

    Does the call processEvents() slow down the application?
    Last edited by Gizmho; 12th July 2006 at 09:37.

  5. #4
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: MainWindow update during computations

    See qt doc /usr/local/qt/doc/html/eventsandfilters.html (Change path accordingly for your installation) or
    Search for "Event filters" (in qt assistant) and select "Qt 4.1 Events and Event Filters"

    You will get all what you need. Happy reading.

  6. #5
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: MainWindow update during computations

    Quote Originally Posted by Gizmho
    Does the call processEvents() slow down the application?
    Probably just the price of a function call, multiplied by how many times you need to call it, as well as the cost of processing the events. But that's just the price of having your application "feel" like it's doing multitasking and being responsive. You can't get things for free. For the most part, the performance drop should be negligible.
    Software Engineer



  7. #6
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow update during computations

    how does this handle the following thing:

    Qt Code:
    1. computing very much A
    2. break -> processEvents()
    3. compute something
    4. compute something
    5. compute very much B
    6. continue with A
    7. computing very much A
    8. ..
    To copy to clipboard, switch view to plain text mode 


    will A continue only after B is finished?
    so when i call A in B, then i'll get a recursion?

    regards..
    aman..

  8. #7
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: MainWindow update during computations

    Yes, according to the docs, processEvents() processes all pending events before returning - all this work is done in the same thread. So, if function A() calls processEvents(), and one of the event handlers (perhaps B()) then calls A() again, there might be some recursion. I don't think it would be infinite recursion; the event being processed must be removed from the list of pending events before getting processed, and it looks like Qt follows this at least in Windows (in qeventdispatcher_win.cpp):
    msg = d->queuedUserInputEvents.takeFirst();

    The funny result is that events might be processed in reverse order as it finishes its recursion; but the processing should go on as the pending event list is whittled away.
    Software Engineer



  9. #8
    Join Date
    Jul 2006
    Posts
    79
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MainWindow update during computations

    thank you, that helped me understand the system..

    regards..
    aman..

Similar Threads

  1. Paint MainWindow Regions
    By pedros09 in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2006, 09:43
  2. mainwindow does not refresh
    By edb in forum Qt Programming
    Replies: 22
    Last Post: 25th January 2006, 16:42
  3. Update a row
    By dragon in forum Newbie
    Replies: 9
    Last Post: 17th January 2006, 17:11

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.