Results 1 to 5 of 5

Thread: Maximum value of ProgressBar

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Maximum value of ProgressBar

    Hello,

    I want to ask about whether i can or not to set the maximum value of progress bar to value bigger than the max int value.

    for example,

    I have this case and I want to use prgressbar for it.

    I have 2 differetnt loops.

    the first loop is O(n)

    the 2nd loop is O(n*m)
    (m !=n)
    Qt Code:
    1. for(i .... n )
    2. {
    3. ...
    4. ...
    5. ..
    6.  
    7. }
    8.  
    9. for (i m)
    10. {
    11.  
    12. for(j n)
    13. {
    14. ......
    15. ......
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 


    These loops takes long time to finish, so i want to set progress bar

    I tried to set the maximum value to

    n + (n*m)

    and and the increse its value by 1 for each iteration, this way works fine when the n and m are not too big, but when n and m are really big such as ( 2 M) this way wont works
    as the
    Qt Code:
    1. QProgressBar.setMaximum(int)
    To copy to clipboard, switch view to plain text mode 
    take "int" and int type can not hold big values.

    so plz, dose any one have an idea of how I can solve this issue.

    thanks

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

    Default Re: Maximum value of ProgressBar

    If you have such big loops then setting value for the progress bar inside the most inner loop is not a good idea. Each time you set a new value and want it to be reflected in your UI, you need to force Qt to process its events. If you do that inside the most-inner loop, events are going to be processed a lot. Each time they are processed, the application is not doing the tasked you wanted it to but instead spins the event loop. This makes your task execute much longer (for some tasks it might take longer than tasks themselves). Consider setting new value for the progress bar in the most outer loop. This will reduce processing time significantly. You can't force the default QProgressBar to accept anything else than an int, you'd have to roll out your own progress bar implementation (it's not that complicated, you could subclass QProgressBar and provide your own counters) but I strongly suggest to avoid it.
    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. The following user says thank you to wysota for this useful post:

    jesse_mark (9th January 2013)

  4. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximum value of ProgressBar

    the issue is, that I have two separate loops, the first one use "n" and the other loop "nested loops" the outer loop use "m".

    so if i just used (n+m) as my maximum value for progress Bar, i end up with not really reflective progress bar,
    In case of N away bigger than M, the progress bar will almost reach 90% from the first loop, and come the 2nd loop and feel its stuck as the inner loop will be too huge compared to the outer loop.
    Last edited by jesse_mark; 9th January 2013 at 15:49.

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

    Default Re: Maximum value of ProgressBar

    You can always go for a hybrid approach. Calculate m*n and divide it by some constant (e.g. 1000 or 100000). Then increment the progress bar value by 1 for each 1000 or 100000 iterations of the inner loop.
    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.


  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Maximum value of ProgressBar

    Or store progress and total in double and use the ratio as a percentage of a fixed, large integer value.

    Cheers,
    _

Similar Threads

  1. to create a circle progressbar
    By wagmare in forum Qt Programming
    Replies: 8
    Last Post: 16th November 2015, 22:45
  2. progressbar from right to left.
    By kumari arpita in forum Newbie
    Replies: 2
    Last Post: 1st August 2012, 07:22
  3. Confused with progressbar
    By hakermania in forum Newbie
    Replies: 2
    Last Post: 23rd January 2011, 10:47
  4. Indefinite ProgressBar
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:02
  5. Progressbar problem
    By thae in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 11:48

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.