In Qt, you can use Qprogressbar or Qprogressdialog to achieve a progress bar.
Use of Qprogressbar
First drag a button and a progress bar widget in the designer and initialize it as follows
Add: The following two sentences are written in the MainWindow constructor.
ui->progressBar->setRange(0,50000-1);
UI->progressbar->setvalue(0);
Event handling for the button:
void MainWindow:: on_pushbutton_clicked
{
For (int i=0; I<50000; I
For(int J=0; J<20000; J
UI->progressbar->setvalue(i
This will show the progress bar, which calculates the percentage automatically and shows
How to use Qprogressdialog
The use of Qprocessdialog is similar, except that it is displayed as a dialog box, and it also provides a Cancel button to cancel the operation. Qprocessdialog will automatically calculate that percentage and display it.
void MainWindow:: on_pushbutton_clicked
Qprogressdialog Process( This
Process. Setlabeltext(tr("Processing ..." )
Process. SetRange(0,50000
Process. Setmodal(true);
Process. Setcancelbuttontext(tr("Cancel"));
For(int i=0; I<50000; I
For(int J=0; J<20000; J
Process. SetValue(i
If(Process. wascanceled
Break
Transferred from:http://blog.sina.com.cn/s/blog_6151770b0100ndle.html
You can only turn!
Use of progress bar in QT