Results 1 to 7 of 7

Thread: How to show a progress bar without knowing size of file being loaded

  1. #1
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to show a progress bar without knowing size of file being loaded

    I was curious if anyone could show me/tell me how to get a progress bar to show a file being loaded when you do not know the size of the file. I have used a QProgressDialog before but that was when I knew the file size but now that I do not know the file size how do I get the same type of Progress bar to show up as you do when you know the file size and are capable of using QProgressDialog. If my question is unclear please don't be afraid to question me.

    Thanks for any help!

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    What I do in that case is show a progressbar that goes left to right and back. This is what they call a 'busy indicator'. With QProgressbar, just set min/max to 0.

  3. #3
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    Alright is the above any different then changing the mouse to a timer symbol? Currently that is what I do, I use the QApplication::setOverrideCursor(Qt::WaitCursor) then after the loading is done reset it back to normal using QApplication::restoreOverrideCursor(). I am just curious if there is a way to show the actual bar indicator without knowing the sizes of the files?

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    No. When you don't know when you're finished how should you know when you're xx% finished?
    Last edited by nightghost; 23rd February 2011 at 17:41. Reason: spelling corrections

  5. #5
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    No. When you don't know when you're finished how should you now when you're xx% finished?
    That's what I thought but it never hurts to ask and find out if some coding guru figured out a way to make magic happen . Thanks for letting me know

  6. #6
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    Quote Originally Posted by jshafferman View Post
    Alright is the above any different then changing the mouse to a timer symbol? Currently that is what I do, I use the QApplication::setOverrideCursor(Qt::WaitCursor) then after the loading is done reset it back to normal using QApplication::restoreOverrideCursor(). I am just curious if there is a way to show the actual bar indicator without knowing the sizes of the files?
    it is different and I find it way more indicative that the app is doing something compared to the mouse hourglass - however that's just my opinion.

  7. #7
    Join Date
    Dec 2010
    Posts
    76
    Thanks
    13
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to show a progress bar without knowing size of file being loaded

    I know this is an old thread that I started but I thought I would show how I am able to get a progress bar to show when I don't know the file size prior to load.

    Basically what I do is get the file with QFile and then pass it to a QTextStream to start parsing the text for my application. I do this by doing the normal QTextStream in(&inFile) where inFile is the QFile.

    Before I start parsing I set the max to inFile.bytesAvailable() by this: int max = inFile.bytesAvailable();.

    Then run a loop doing this while(!in.atEnd()) and inside of this loop I update a counter by using the following counter = max - inFile.bytesAvailable() thus getting the progress bar to increment from 0% to 100%!

    I just thought I would post this because I found that it is sort of an interesting work around and I am sure this is not an original solution lol.

Similar Threads

  1. Widget to show multiple progress %ages in the same bar?
    By adith387 in forum Qt Programming
    Replies: 2
    Last Post: 7th January 2011, 17:02
  2. Replies: 0
    Last Post: 26th October 2010, 17:59
  3. How show progress of slow a operation?
    By shud in forum Qt Programming
    Replies: 9
    Last Post: 3rd December 2009, 22:10
  4. Show progress of a time consuming operation
    By rainman110 in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 12:07
  5. Not show the progress bars under another window
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 13th March 2006, 17:22

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.