Varun Chitre
Varun Chitre

Reputation: 3220

Increasing progress bar value by decimal value and few more problems in Qt

I have following problems.

A) How can i increase value of progress bar by decimal values? I tried

ui->progressBar->setValue(0.5); and increased this using while loop by added 0.5. But all I got is empty progress bar. Any idea why?

p.s:I got warning 'This statement has no effect' on the line ui->progressBar->setValue(0.5);

B) While making a progress bar I made a while loop with progress bar value increments by 1 and added Sleep(600) so that progress bar doesn't complete very fast. That isn't the problem, my problem is while the progress bar is increasing, my app lags a lot. I tried putting QCoreApplication::processEvents(); all over my while loop and all over in my code but that didn't work. What to do?

Upvotes: 1

Views: 2164

Answers (2)

Dan Milburn
Dan Milburn

Reputation: 5718

Regarding B), do not use Sleep in the main thread. Of course this will make your application unresponsive, because no repaints or input event handling can occur while the thread is sleeping. Instead use a QTimer connected to a slot which increments your progress bar value.

Upvotes: 1

TonyK
TonyK

Reputation: 17124

QProgressBar::setValue takes an int parameter. 0.5 converted to int is 0, as any fule kno. So you are effectively calling setValue (0).

To do this properly, you have to call setMinimum and setMaximum, and then scale the floating-point number by the appropriate factor.

But I must confess, I'm puzzled by your "statement has no effect" warning. Are you sure about that?

Upvotes: 3

Related Questions