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..
Code:
progressBar.setMinimum(0);
progressBar.setMaximum(0);
fn();
progressBar.hide();
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*
Re: busy progress bar without thread ?
you should call the progress bar in your fn() function.
Show your fn() fucntion code.
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
Code:
fn()
{
fn1();
prgressBar.show();
fn2();
progressBar.show();
}
But it doesnt helps me :(
Thanks,
*npc*
Re: busy progress bar without thread ?
but where do you call setValue()?
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*
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
Re: busy progress bar without thread ?
I think you're missing some QCoreApplication::processEvents() calls...
Re: busy progress bar without thread ?
Wysota - I think so too, but even that wont help if he doesen't call setValue()...;)
Re: busy progress bar without thread ?
Quote:
I think you're missing some QCoreApplication::processEvents() calls...
Exactly.. Thanks Wysota.
Now its working fine for me.. I called QCoreApplication::processEvents() in sub functions.
But I never called setValue() anywhere :)
Re: busy progress bar without thread ?
So how is the progress bar incremented?
Quote:
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().
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].
Re: busy progress bar without thread ?
Oh I see - it didn't sink in that he used [0,0].
Sorry about that. :)
Re: busy progress bar without thread ?
how to make QProgress bar busy works
my code
Code:
ui.initStatus->setRange(0,0);
qApp->processEvents ( );
but, nothing happens.
thanks!
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.
Re: busy progress bar without thread ?
Code:
for( int i=0; i<1000; i++ ){
ui.initStatus->setMaximum(0);
ui.initStatus->setMinimum(0);
qApp->processEvents();
}
Don't work
Code:
ui.initStatus->setMaximum(0);
ui.initStatus->setMinimum(0);
for( int i=0; i<1000; i++ )
qApp->processEvents();
Don't work
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.
Re: busy progress bar without thread ?
Code:
ui.initStatus->setMaximum(0);
ui.initStatus->setMinimum(0);
this
->timer
= new QTimer(this);
connect(this->timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
this->timer->start(100);
void advanceProgressBar(){
qApp->processEvents();
}
Don't work
how...
thanks!!
Re: busy progress bar without thread ?
the bar does not move!
don't increment...it is stopped
Re: busy progress bar without thread ?
Works for me:
Code:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
progressBar.setMinimum(0);
progressBar.setMaximum(0);
progressBar.show();
return app.exec();
}
Re: busy progress bar without thread ?
Quote:
Originally Posted by
jpn
Works for me:
Code:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
progressBar.setMinimum(0);
progressBar.setMaximum(0);
progressBar.show();
return app.exec();
}
Don't work... see
Code:
progressBar->setMaximumHeight(16);
progressBar->setMaximumWidth(200);
progressBar->setTextVisible(false);
progressBar->setMaximum(0);
progressBar->setMinimum(0);
progressBar->show(); // ??? don't move the bar
window.statusBar()->addPermanentWidget(progressBar);
window.statusBar()->showMessage("Loading");
window.show();
app.exec();