PDA

View Full Version : busy progress bar without thread ?



npc
31st March 2007, 11:36
Hi,

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




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*

high_flyer
31st March 2007, 11:52
you should call the progress bar in your fn() function.
Show your fn() fucntion code.

npc
31st March 2007, 12:08
It is a big code which is used to collect the system informations.

I called the progress bar in fn() like this



fn()
{

fn1();
prgressBar.show();
fn2();
progressBar.show();

}


But it doesnt helps me :(

Thanks,
*npc*

high_flyer
31st March 2007, 12:23
but where do you call setValue()?

npc
31st March 2007, 13:00
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*

high_flyer
31st March 2007, 13:04
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

wysota
31st March 2007, 13:19
I think you're missing some QCoreApplication::processEvents() calls...

high_flyer
31st March 2007, 13:31
Wysota - I think so too, but even that wont help if he doesen't call setValue()...;)

npc
31st March 2007, 13:59
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 :)

high_flyer
31st March 2007, 14:01
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().

wysota
31st March 2007, 14:09
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].

high_flyer
31st March 2007, 14:11
Oh I see - it didn't sink in that he used [0,0].
Sorry about that. :)

bmn
4th December 2008, 17:56
how to make QProgress bar busy works

my code


ui.initStatus->setRange(0,0);
qApp->processEvents ( );

but, nothing happens.

thanks!

jpn
4th December 2008, 18:00
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.

bmn
4th December 2008, 18:37
for( int i=0; i<1000; i++ ){
ui.initStatus->setMaximum(0);
ui.initStatus->setMinimum(0);
qApp->processEvents();
}

Don't work


ui.initStatus->setMaximum(0);
ui.initStatus->setMinimum(0);
for( int i=0; i<1000; i++ )
qApp->processEvents();

Don't work

jpn
4th December 2008, 18:53
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.

bmn
4th December 2008, 18:59
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!!

bmn
4th December 2008, 19:02
the bar does not move!
don't increment...it is stopped

jpn
4th December 2008, 19:09
Works for me:


// main.cpp
#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QProgressBar progressBar;
progressBar.setMinimum(0);
progressBar.setMaximum(0);
progressBar.show();
return app.exec();
}

bmn
4th December 2008, 19:24
Works for me:


// main.cpp
#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QProgressBar progressBar;
progressBar.setMinimum(0);
progressBar.setMaximum(0);
progressBar.show();
return app.exec();
}


Don't work... see


QApplication app(argc, argv);
QMainWindow window;
QProgressBar* progressBar = new QProgressBar(&window);
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();

jpn
4th December 2008, 19:30
Which Qt version are you using? I recall seeing a bug in the past that with some specific style that you had to set a value != 0 to make the busy indicator to work.

bmn
4th December 2008, 19:38
I am using Qt4

jpn
4th December 2008, 19:43
I am using Qt4
Well, that's not very exact definition. The first version of Qt 4 was released a few years ago. There have been quite a few minor and patch version upgrades since then. What is the exact version eg. 4.x.y? Which style are you using? You can see the bug situation in the task-tracker (http://trolltech.com/developer/task-tracker/index_html?searchstr=QProgressBar+busy&method=advsearch&bugs=on&sugs=on).

bmn
4th December 2008, 19:47
Well, that's not very exact definition. The first version of Qt 4 was released a few years ago. There have been quite a few minor and patch version upgrades since then. What is the exact version eg. 4.x.y? Which style are you using? You can see the bug situation in the task-tracker (http://trolltech.com/developer/task-tracker/index_html?searchstr=QProgressBar+busy&method=advsearch&bugs=on&sugs=on).

QMake version 2.01a
Using Qt version 4.2.1 in /usr/lib/qt4/lib

jpn
4th December 2008, 19:50
QMake version 2.01a
Using Qt version 4.2.1 in /usr/lib/qt4/lib
The current stable version of Qt is 4.4.3. Probably it's time to upgrade. Anyway, have you tried the trick setting the value to something != 0? And again, which style you are using?

bmn
4th December 2008, 19:55
The current stable version of Qt is 4.4.3. Probably it's time to upgrade. Anyway, have you tried the trick setting the value to something != 0? And again, which style you are using?

Default Style
this is the test


int main(int argc, char *argv[]){
QApplication app(argc, argv);
QMainWindow window;
QProgressBar* progressBar = new QProgressBar(&window);
progressBar->setMaximumHeight(16);
progressBar->setMaximumWidth(200);
progressBar->setTextVisible(false);
progressBar->setMaximum(0);
progressBar->setMinimum(0);
progressBar->setValue(1); // ??? don't move the bar
window.statusBar()->addPermanentWidget(progressBar);
window.statusBar()->showMessage("Loading");
window.show();
app.exec();
}

jpn
4th December 2008, 20:01
First of all, could you finally start using appropriate [code] tags, please? I already sent instructions to you.

Secondly, the "default style" depends on the environment. The following piece of code prints out which style is the default style for you:


qDebug() << app.style()->objectName();

You can try different styles by passing it as a command line argument:

./myapp -style windows

You can try different styles like "windows", "plastique", "cleanlooks" etc. Does any of them work?

bmn
4th December 2008, 20:32
First of all, could you finally start using appropriate [code] tags, please? I already sent instructions to you.

Secondly, the "default style" depends on the environment. The following piece of code prints out which style is the default style for you:


qDebug() << app.style()->objectName();

You can try different styles by passing it as a command line argument:

./myapp -style windows

You can try different styles like "windows", "plastique", "cleanlooks" etc. Does any of them work?

Sorry i will start to use code!!

My default style is cleanlooks, change to windows and WORKS, but, only with windows style.
I will try to set windows style as default
thanks!!

jpn
4th December 2008, 20:39
So you're probably hit by this bug: QProgressBar "busy indicator" mode doesn't work in Cleanlooks style. It was fixed in Qt 4.3.0. So updating to a recent version of Qt would help as suggested earlier.

bmn
4th December 2008, 20:42
So you're probably hit by this bug: QProgressBar "busy indicator" mode doesn't work in Cleanlooks style. It was fixed in Qt 4.3.0. So updating to a recent version of Qt would help as suggested earlier.

Thanks *JPN*
I use Red Hat system, i will try update may qt!!!

Thanks again!!!

bmn
5th December 2008, 17:39
I update my qt4.2.1 version to qt4.4.3,
I did:
qmake -project
qmake myproject.pro
make

WORKS!

but,
I try to play and happens

./mypoject: undefined symbol: _ZN10QBoxLayout10setSpacingEi

And now?? What do I do?

thanks angain,

jpn
5th December 2008, 17:42
Make clean and rebuild.

bmn
5th December 2008, 17:49
I did:
make clean
make

on eclipe appears:

/home/alexwell/workspace/smartcardtools/Debug/SmartCardTools: symbol lookup error: /home/alexwell/workspace/smartcardtools/Debug/SmartCardTools: undefined symbol: _ZN10QBoxLayout10setSpacingEi

bmn
11th December 2008, 17:16
Thanks *JPN* !!!

I remove all qts and reinstall, now its working...

Thanks again...

sheeeng
23rd July 2009, 09:29
It works for me in Qt 4.5.1's QProgressBar.

Just set progressBar.setMinimum(0); progressBar.setMaximum(0); in the designer works for me. The progressBar.value would be -1 automatically in designer.

Hope this helps.