Page 1 of 2 12 LastLast
Results 1 to 20 of 35

Thread: busy progress bar without thread ?

  1. #1
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile busy progress bar without thread ?

    Hi,

    I am using progress bar which showing a busy mode ( minimum = maximum = 0 ).
    and my code goes like this..

    Qt Code:
    1. progressBar.setMinimum(0);
    2. progressBar.setMaximum(0);
    3. fn();
    4. progressBar.hide();
    To copy to clipboard, switch view to plain text mode 

    When the process running in fn() the progress bar is not showing the busy mode.

    But I want to show the progressbar in a busy mode till the fn retuns.
    should I use threads for this ? or is there any easy way ?

    Thanks
    *npc*

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    you should call the progress bar in your fn() function.
    Show your fn() fucntion code.

  3. #3
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    It is a big code which is used to collect the system informations.

    I called the progress bar in fn() like this

    Qt Code:
    1. fn()
    2. {
    3.  
    4. fn1();
    5. prgressBar.show();
    6. fn2();
    7. progressBar.show();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    But it doesnt helps me

    Thanks,
    *npc*

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    but where do you call setValue()?

  5. #5
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    Because I want to show busy indicator in progress bar, I set minimum and maximum values as 0.

    So what is the need of calling setvalue ? ..if it necessary what value have to send ?

    Thanks,
    *npc*

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    Well lets see -
    How can the progress bar know, when to progress the bar?
    I suggest you read the docs first:
    http://doc.trolltech.com/4.2/qprogressbar.html

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

    Default Re: busy progress bar without thread ?

    I think you're missing some QCoreApplication::processEvents() calls...

  8. The following user says thank you to wysota for this useful post:

    npc (31st March 2007)

  9. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    Wysota - I think so too, but even that wont help if he doesen't call setValue()...

  10. #9
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    I think you're missing some QCoreApplication:rocessEvents() calls...
    Exactly.. Thanks Wysota.

    Now its working fine for me.. I called QCoreApplication:rocessEvents() in sub functions.

    But I never called setValue() anywhere

  11. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    So how is the progress bar incremented?
    The progress bar uses the concept of steps. You set it up by specifying the minimum and maximum possible step values, and it will display the percentage of steps that have been completed when you later give it the current step value. The percentage is calculated by dividing the progress (value() - minimum()) divided by maximum() - minimum().

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

    Default Re: busy progress bar without thread ?

    It's not, it's just spinning all the time like in Star Trek or Knightrider. This is a special case of using a progress bar that is activated by setting the range of values to [0,0].

  13. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: busy progress bar without thread ?

    Oh I see - it didn't sink in that he used [0,0].
    Sorry about that.

  14. #13
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: busy progress bar without thread ?

    how to make QProgress bar busy works

    my code

    Qt Code:
    1. ui.initStatus->setRange(0,0);
    2. qApp->processEvents ( );
    To copy to clipboard, switch view to plain text mode 

    but, nothing happens.

    thanks!
    Last edited by jpn; 4th December 2008 at 17:59. Reason: missing [code] tags

  15. #14
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: busy progress bar without thread ?

    Calling processEvents() once before a busy loop won't do the trick. You have to call it every now and then during the busy loop. You must let the application to process its events meanwhile you do the calculation. Otherwise the application won't be able to update any widget.
    J-P Nurmi

  16. #15
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: busy progress bar without thread ?

    Qt Code:
    1. for( int i=0; i<1000; i++ ){
    2. ui.initStatus->setMaximum(0);
    3. ui.initStatus->setMinimum(0);
    4. qApp->processEvents();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Don't work

    Qt Code:
    1. ui.initStatus->setMaximum(0);
    2. ui.initStatus->setMinimum(0);
    3. for( int i=0; i<1000; i++ )
    4. qApp->processEvents();
    To copy to clipboard, switch view to plain text mode 

    Don't work
    Last edited by jpn; 4th December 2008 at 18:50. Reason: missing [code] tags

  17. #16
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: busy progress bar without thread ?

    What does "Don't work" mean? Is the progress bar visible at all? Is the user interface responsible? The latter version is the more correct one, there is no need to set the range many times.
    J-P Nurmi

  18. #17
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: busy progress bar without thread ?

    Qt Code:
    1. ui.initStatus->setMaximum(0);
    2. ui.initStatus->setMinimum(0);
    3. this->timer = new QTimer(this);
    4. connect(this->timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
    5. this->timer->start(100);
    6.  
    7. void advanceProgressBar(){
    8. qApp->processEvents();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Don't work

    how...
    thanks!!
    Last edited by jpn; 4th December 2008 at 19:06. Reason: missing [code] tags

  19. #18
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: busy progress bar without thread ?

    the bar does not move!
    don't increment...it is stopped

  20. #19
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: busy progress bar without thread ?

    Works for me:
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QProgressBar progressBar;
    8. progressBar.setMinimum(0);
    9. progressBar.setMaximum(0);
    10. progressBar.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  21. #20
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: busy progress bar without thread ?

    Quote Originally Posted by jpn View Post
    Works for me:
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QProgressBar progressBar;
    8. progressBar.setMinimum(0);
    9. progressBar.setMaximum(0);
    10. progressBar.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Don't work... see

    Qt Code:
    1. QApplication app(argc, argv);
    2. QMainWindow window;
    3. QProgressBar* progressBar = new QProgressBar(&window);
    4. progressBar->setMaximumHeight(16);
    5. progressBar->setMaximumWidth(200);
    6. progressBar->setTextVisible(false);
    7. progressBar->setMaximum(0);
    8. progressBar->setMinimum(0);
    9.  
    10. progressBar->show(); // ??? don't move the bar
    11.  
    12. window.statusBar()->addPermanentWidget(progressBar);
    13. window.statusBar()->showMessage("Loading");
    14. window.show();
    15. app.exec();
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 4th December 2008 at 19:31. Reason: missing [code] tags

Similar Threads

  1. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  2. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  3. Replies: 11
    Last Post: 7th July 2006, 13:09
  4. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44
  5. Replies: 2
    Last Post: 6th January 2006, 21:15

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.