Results 1 to 8 of 8

Thread: Simple QProgressDialog without multi threading

  1. #1
    Join Date
    Nov 2010
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    24

    Default Simple QProgressDialog without multi threading

    I am trying to set up a simple QProgressDialog while a for loop is taking place without using mutlithreading. I followed the Keeping the GUI Responsive but I cannot get it working:

    Qt Code:
    1. QProgressDialog progress("Copying files...", "Abort Copy", 0, myModel->model->rowCount(), this);
    2. progress.setWindowModality(Qt::WindowModal);
    3. // progress.show();
    4.  
    5.  
    6. for( int i = 0; i< linesetIndexes.size()-1; i++ )
    7. {
    8.  
    9. progress.setValue(i);
    10. QCoreApplication::processEvents();
    11. if (progress.wasCanceled())
    12. break;
    13. ......//proccessing
    14.  
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Simple QProgressDialog without multi threading

    Please explain what you mean by "cannot get it working". The progress dialog shouldn't need processEvents(), the call is embeded into QProgressDialog::setValue().
    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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Simple QProgressDialog without multi threading

    A possible issue is that you set the progress dialog's range to 0 to myModel->model->rowCount() and then proceed to feed it values from 0 to linesetIndexes.size()-2 in your for loop. Only you know if the two upper bounds are related to each other.

  4. #4
    Join Date
    Nov 2010
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    24

    Default Re: Simple QProgressDialog without multi threading

    @wysota: The for-loop does some heavy calculations. At that phase, the application looks like it hangs, but it does not. At the end of the calculations the application comes back to life and presents them. It is only then when the progress bar appears with value 100%. If I uncomment:
    Qt Code:
    1. // progress.show();
    To copy to clipboard, switch view to plain text mode 
    then the box of the progress bar appears with the window title and nothing else in it. At the end of the calculations the progress bar appears again with value 100%

    @ChrisW67: the linesetIndexes.size()-1 is known before the for-loop starts and it is always greater than 5 or six. So there it should be some progress

  5. #5
    Join Date
    Nov 2010
    Posts
    142
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    24

    Default Re: Simple QProgressDialog without multi threading

    any ideas?

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

    Default Re: Simple QProgressDialog without multi threading

    I'd have to see 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
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Simple QProgressDialog without multi threading

    Quote Originally Posted by fatecasino View Post
    @ChrisW67: thmyModel->model->rowCount()e linesetIndexes.size()-1 is known before the for-loop starts and it is always greater than 5 or six. So there it should be some progress
    I think you have missed the point. The range of values you have told the dialog to expect and the range of values you subsequently feed it through calls to setValue may not be comparable, and you haven't addressed that point. For example: if myModel->model->rowCount() is 1000 and you feed the values from 0 to 5 or 6 into the progress dialog through setValue() then the bar is hardly going to move significantly even if it is working.

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: Simple QProgressDialog without multi threading

    Another problem: the "processing" step, left blank in the example code, might take varying amounts of time to complete per iteration. If execution time per iteration varies widely, you'll get hangs between some updates and not others.

Similar Threads

  1. Multi-threading in Console QCoreApplication
    By Dazed in forum Qt Programming
    Replies: 4
    Last Post: 4th July 2010, 16:27
  2. Slow Multi-Threading
    By AwDogsgo2Heaven in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2009, 22:36
  3. Multi-threading
    By lixo1 in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2009, 14:22
  4. Multi threading ...
    By kiranraj in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 17:51
  5. Multi-threading
    By shamik in forum Qt Programming
    Replies: 15
    Last Post: 28th November 2006, 11:22

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
  •  
Qt is a trademark of The Qt Company.