PDA

View Full Version : Busy Indicator using QProgressDialog??



qtzcute
1st June 2009, 06:56
I am trying to copy /dev/mem to another location and want a 'busy indicator progressDialog' (in which a fluid moves to and fro in a progress bar) to show that the copying process is going on.

Qt provides two widgets for showing progress
1. QProgressBar
2. QProgressDialog

if we set both setMinimum and setMaximum equal to zero in 'QProgressBar' then i get the to and fro functionality but although setMaximum and setMaximum properties are available for 'QProgressDialog' too; setting them to zero do not give me the required functionality.

I hope i made myself clear. Please suggest some solution..

Following link contains the snippet of the code



QProgressDialog progress("Copying files...", "Abort Copy", 0, 0);
progress.setWindowModality(Qt::WindowModal);
progress.setMinimumDuration(0);

QObject *parent;
QString temp="checking";
QString program = "dd if=/dev/mem of=/home/usman/copiedFile.dt"
QProcess *myProcess= new QProcess(parent);
QCoreApplication::processEvents();

progress.setRange(0, 1);
progress.setValue(0);
progress.setRange(0, 0);

nish
1st June 2009, 07:12
looking at the QProgressDialog docs...


Progress starts at the value set by setMinimum(), and the progress dialog shows that the operation has finished when you call setValue() with the value set by setMaximum() as its argument.
The dialog automatically resets and hides itself at the end of the operation. Use setAutoReset() and setAutoClose() to change this behavior.

so it looks like this dialog is not ment for showing busy states..

try this if it works...i am not too sure


QProgressBar* bar=new QProgressBar;
progressDialog->setBar(bar);
bar->setMinimum(0);bar->setMaximum(0);
progressDialog->show();

as a last resort u can make your own dialog class .

wysota
1st June 2009, 09:32
Set the range to (0,0) in the first place (before calling setValue) and I think you should obtain what you want.

qtzcute
2nd June 2009, 05:09
setting the value to (0,0) did not solve the problem. And i tried the setBar(QProgressBar *bar) too, suggested by MrDeath, but it also did not result in some thing fruitful.

:(

qtzcute
2nd June 2009, 06:01
After don't having much luck with QProgressDialog...i now turned to ProgressDialog but encountered another problem.

I got the to and fro movement of a blue fluid in the progress bar, depicting the busy state, but i want to make the bar filled with blue fluid at the completion of the operation i am performing.

But problem is that for the busy indicator i need to setMaximum=0. And at the end of process i need to set setMaximum to say 100 and setValue to 100 too.

When i run my app, the later setMaximum seems to overide the previous setMaximum and as soon as the app runs, the progressBar gives a 100% reading with the blue fluid filled comletely in it, without showing any busy indicatior.

If i use the waitForFinished() function of QProcess to wait until my task is finished (and then setting the setMaximum=100 and setValue=100) then my app gets frozen and i neither get a busy indicatior nor a blue fluid filled bar.

Following is the code


QObject *parent;
progressBar->setMaximum(0);
progressBar->setMinimum(0);

QString program = "dd if=/dev/mem of=";
program.append(lineEdit_saveAt->text());
QProcess *myProcess= new QProcess(parent);
QCoreApplication::processEvents();

myProcess->start(program);

//if myProcess->waitForFinished() {
progressBar->setMaximum(100);
progressBar->setValue(100);
//}


Please suggest something. Thanks

faldzip
2nd June 2009, 06:18
setting the value to (0,0) did not solve the problem.
wysota told you to set the range, not value.

If i use the waitForFinished() function of QProcess to wait until my task is finished (and then setting the setMaximum=100 and setValue=100) then my app gets frozen and i neither get a busy indicatior nor a blue fluid filled bar.
make a slot in which you set the progress filled (max = 100, value = 100) and connect QProcess::finished() to it.

wagmare
2nd June 2009, 08:23
same problem encountered .. in progressDialog setting range or value to 0 is not working .. but its working for QProgressBar ...

wysota
2nd June 2009, 10:05
setting the value to (0,0) did not solve the problem. And i tried the setBar(QProgressBar *bar) too, suggested by MrDeath, but it also did not result in some thing fruitful.

:(

Works for me...


#include <QtGui>

int main(int argc, char **argv){
QApplication app(argc, argv);
QProgressDialog dlg;
dlg.setRange(0,0);
dlg.exec();
}

qtzcute
3rd June 2009, 04:45
@falzip
Thanks..that worked.

@wysota
I wasn't using dlg.exec(). Most probably that was the reason. Thanks for helping.

Qiieha
6th September 2011, 08:28
why so difficult???
use


QProgressDialog progress(this);
progress.setWindowModality(Qt::WindowModal);
progress.setLabelText("working...");
progress.setCancelButton(0);
progress.setRange(0,0);
progress.setMinimumDuration(0);
progress.show();
//do what u want...
progress.cancel();

nish
6th September 2011, 10:53
why so difficult???
use


QProgressDialog progress(this);
progress.setWindowModality(Qt::WindowModal);
progress.setLabelText("working...");
progress.setCancelButton(0);
progress.setRange(0,0);
progress.setMinimumDuration(0);
progress.show();
//do what u want...
progress.cancel();



Did you noticed that this thread is 2 years old and the OP got the answer as well.

Qiieha
6th September 2011, 11:07
I know, but his solution is intricate, and lots of people google for "QProgressDialog busy indicator" and hit on this thread.
So I think it's useful, if there is another working solution, isn't it? :)

nish
6th September 2011, 11:12
well, if you try your code

progress.show();
//do what u want...
progress.cancel();

You will not see the animation in the progress dialog because the event loop would be blocked util your "//do what u want" is finished.

Qiieha
6th September 2011, 11:31
no, I use my code in a couple of programs and it works.