Results 1 to 8 of 8

Thread: occasional frozen QProgressDialog with QFutureWatcher

  1. #1
    Join Date
    Nov 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default occasional frozen QProgressDialog with QFutureWatcher

    Hi,

    I'm having occasional trouble with a QProgressDialog connected to a QFutureWatcher (Qt4.6.2, x11). For roughly one in five occasions where the QFuture calculation is almost instantaneous (but never when it takes several seconds or more), the dialog appears empty with no cancel button or progress bar and can't then be closed.

    Using something like the following (the watcher and dialog can be reused for different calculations):

    Qt Code:
    1. class MyClass {
    2. QProgressDialog mProgress;
    3. QFutureWatcher mWatcher;
    4. };
    5.  
    6. MyClass::MyClass() {
    7. connect(&mWatcher, SIGNAL(finished()), &mProgress, SLOT(reset()));
    8. connect(&mWatcher, SIGNAL(progressValueChanged(int)), &mProgress, SLOT(setValue(int)));
    9. connect(&mWatcher, SIGNAL(progressRangeChanged(int,int)), &mProgress, SLOT(setRange(int,int)));
    10. connect(&mProgress, SIGNAL(canceled()), &mWatcher, SLOT(cancel()));
    11. connect(&mWatcher, SIGNAL(canceled()), &mProgress, SLOT(cancel()));
    12. }
    13.  
    14. void MyClass::calculate() {
    15. mWatcher.setFuture(QtConcurrent::map(begin(), end(), Calculator()));
    16. }
    To copy to clipboard, switch view to plain text mode 

    My initial thought was that the map completes before all connections to the watcher can be made. However I have tried connecting debugging printing slots to the QFutureWatcher and all appropriate signals are being sent and received in the appropriate order. mWatcher.isRunning() always returns true immediately after the setFuture() call.

    One other possibility would be as the manual says:
    Note that if you set a new maximum (using setMaximum() or setRange()) that equals your current value(), the dialog will not close regardless
    However debug printing shows this is also not the case.

    Any ideas would be gratefully received.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    How large is your map? Is it possible that jobs are completed so fast that the GUI thread doesn't have time to rerender the dialog before a subsequent task ends? In other words, maybe the dialog gets starved by the background tasks?
    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.


  3. #3
    Join Date
    Nov 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    Generally between 1 & 1000 items in the map, however sometimes it already contains most of the results and doesn't need much further processing (ie. the map takes from <<1s to ~60s). For whatever reason, very fast completion can cause this problem and it may well be thread starvation as you say.

    However wouldn't the dialog be re-rendered in the GUI thread once the map has finished? In fact in this case it just contains an empty gray rectangle, but does repaint (only as the rectangle) when resized or obscured by other windows. I don't understand how it can get stuck in such a state and what I can do about it.

    thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    Quote Originally Posted by ibex View Post
    However wouldn't the dialog be re-rendered in the GUI thread once the map has finished? In fact in this case it just contains an empty gray rectangle, but does repaint (only as the rectangle) when resized or obscured by other windows. I don't understand how it can get stuck in such a state and what I can do about it.
    So you mean it stays that way regardless of what your application is doing? Can you resize other windows and observe them being repainted correctly?
    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.


  5. #5
    Join Date
    Nov 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    Yes it stays that way until another map operation is started. Usually, and always if it takes several seconds, the subsequent map causes the QProgressDialog to recover normal behaviour and hide on completion. When the QProgressDialog is not working, the rest of the application still behaves correctly.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    Could you try to prepare a minimal compilable example reproducing the problem?
    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.


  7. #7
    Join Date
    Nov 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    Yes, I will see if I can recreate it.

  8. #8
    Join Date
    Nov 2009
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: occasional frozen QProgressDialog with QFutureWatcher

    progress.zip is a small example based on a Qt one. Unfortunately I have only managed to recreate the problem twice with it. Pressing the run button will start the map operation, and after many presses the progress dialog may fail (it is normally not shown with the coded constants due to the short run time).

    I have tried changing the size of the map task, and adding a slow paintEvent() method to the window but can't yet make the problem more repeatable. I can't think of any other relevant differences to my application at the moment.

Similar Threads

  1. QFutureWatcher finished() signal not working
    By DiamonDogX in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2011, 18:27
  2. Replies: 2
    Last Post: 23rd August 2010, 16:41
  3. Strange behaviour of QFutureWatcher on windows
    By spud in forum Qt Programming
    Replies: 0
    Last Post: 22nd July 2010, 16:47
  4. How to use progressTextChanged() signal in QFutureWatcher
    By DiamonDogX in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 15:41
  5. Frozen? ... no ... calling 01800 Database
    By chaosgeorge in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2006, 13:06

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.