Results 1 to 3 of 3

Thread: Can I call setRange multiple times for QProgressBar ?

  1. #1
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Can I call setRange multiple times for QProgressBar ?

    Hello

    I have long operation that needs to report about progress. The operation have multiple loops inside itself, and each loop counter is not known until runtime. So, I was thinking that I can call setRange multiple times on my progress bar , with the different counter values.Something like this , pseudo code :

    Qt Code:
    1. void MyLongProcedure(QProgressBar* bar)
    2. {
    3.  
    4. int counter1=calc_counter1();
    5. bar->setRange(1,counter1);
    6. for(int i=0;i<counter1;i++)
    7. {
    8. // do something here
    9. bar->SetValue(i);
    10. }
    11.  
    12. int counter2=calc_counter2();
    13. bar->setRange(1,counter2);
    14. for(int i=0;i<counter2;i++)
    15. {
    16. //do something here
    17. bar->setValue(counter1+i);
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    I am expecting I can do this, and the progress bar should update itself accordingly, i.e continue where it ends with the first loop.

    I made simple test , with QProgressDialog since it uses qProgressBar to see if this is supported, but
    after the first loop, the progress bar is reset, and with the second loop it starts anew. Whats wrong ?
    Qt Code:
    1. dlg.setWindowModality(Qt::WindowModal);
    2. dlg.setMinimumDuration(0);
    3. dlg.setRange(1,20000);
    4. for(int i=1;i<10000;i++)
    5. {
    6. // do something here
    7. dlg.setValue(i);
    8.  
    9. if (dlg.wasCanceled())
    10. break;
    11. }
    12.  
    13. dlg.setRange(1,30000);
    14. for(int j=0;j<20000;j++)
    15. {
    16. //do something here
    17. dlg.setValue(1000+j);
    18. if (dlg.wasCanceled())
    19. break;
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Can I call setRange multiple times for QProgressBar ?

    Just to make sure, you do see that the setvalue in the second loop adds only 1000 and not 10000?

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

    elizabeth.h1 (30th April 2010)

  4. #3
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: Can I call setRange multiple times for QProgressBar ?

    That was it. How silly, I missed one zero. Thank you

Similar Threads

  1. Replies: 3
    Last Post: 26th October 2009, 19:11
  2. Replies: 0
    Last Post: 21st September 2009, 17:25
  3. Contex menu appear multiple times
    By kubas in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2009, 14:55
  4. how to calculate difference b/w two times
    By dummystories in forum Newbie
    Replies: 1
    Last Post: 9th March 2009, 13:58
  5. filterAcceptRows() is being called many times for same souceRow.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2009, 03:49

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.