Results 1 to 5 of 5

Thread: Progressbar problem

  1. #1
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    1

    Default Progressbar problem

    I have a function

    Qt Code:
    1. void ex
    2. {
    3. long num = 100000;
    4. for(int i=0;i<num;i++)
    5. {
    6. // do something
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    In the mainWindow when I call this function
    I want to have a progress bar that indicates this function is running

    I've used these code


    Qt Code:
    1. void ex()
    2. {
    3. long RowCount = 60000;
    4. QProgressDialog progress(this);
    5. progress.setLabelText("ProgressBar");
    6. progress.setRange(0, RowCount);
    7. progress.setModal(true);
    8. progress.show();
    9. for (long row = 0; row < RowCount; ++row) {
    10. progress.setValue(row);
    11. qApp->processEvents();
    12. if (progress.wasCanceled()) {
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    But the progress bar isn't running except it's increasing percentage
    ( it shows up but not progressing )

    can't you help me !

    thanks in advance !
    Last edited by thae; 4th November 2006 at 04:50.

  2. #2
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Progressbar problem

    Hi,

    I just copied the content of your ex() function and stuck it in the main() of a test application.
    It ran as expected with a progress bar incrementing the text value and the bar position.
    So unfortunately there's not much I can say about why it's not working.

    In terms of architecture though, it would be best not to have the wasCancelled() test inside you for loop. I stuck a message box in this test, but as soon as I clicked ok the loop continued, then the progress bar was still cancelled, so the messagebox kept being displayed.

    This would be a better construct:
    Qt Code:
    1. for (long row = 0; row < RowCount && !progress.wasCanceled(); ++row)
    2. {
    3. progress.setValue(row);
    4. }
    5. if(progress.wasCanceled())
    6. {
    7. QMessageBox::information(0, "Hi", "there", "OK");
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    Also, I left off qApp->processEvents(); and it worked fine, maybe that's causing an issue on your system?


    Steve York

  3. #3
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    1

    Default Re: Progressbar problem

    Thanks Steve !

    But when the thread's finished, the progress bar still showing on the window
    how can i hide it ?
    Last edited by thae; 4th November 2006 at 10:28.

  4. #4
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Progressbar problem

    So is it working now?

    Qt Code:
    1. progress.hide();
    To copy to clipboard, switch view to plain text mode 

    It will obviously still exist until you exit the scope of the code block you create the QProgressDialog in, so depending on your circumstances, you may need to destroy the thing manually.

  5. #5
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    1

    Default Re: Progressbar problem

    thanks stevey !
    It doesn't working because of my windows theme
    when I change windows theme to XP theme It's Ok !

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  3. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 18:24

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.