Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt problem: No QProgressBar animation with minimum and maximum steps set to 0

Tags:

c++

qt

I have got a problem with my QProgressBar and I hope someone got an idea...

I have created a progress dialog with a QProgressBar on my own. I set minimum and maximum steps to 0 so that the progress indicates my program is busy (the animation thing...).

I show() this progress dialog and activated the Qt::WindowModal for this dialog.

The problem: I use this dialog while copying files but the progress bar stops and no animation anymore to indicate my program is still busy. I use the windows function 'SHFileOperation' to copy one directory with a lot of file to a destination. This, of course, produces a lot of load on the system but at least the progress should continue moving.

Any help is appreciated!

Thanks in advance, BearHead

like image 475
BearHead Avatar asked Oct 19 '25 13:10

BearHead


1 Answers

The problem is that the SHFileOperation call will block the main event loop. Therefore, no events will be processed preventing the QProgressBar from being updated.

To fix this you could perform the copy action in a separate thread. The easiest way to go about this is using Qt Concurrent, for example as follows:

QFuture<void> future = QtConcurrent::run(SHFileOperation, ...);
QFutureWatcher<void> watcher;
connect(&watcher, SIGNAL(finished()), dialog, SLOT(close()));

Assuming dialog is a pointer to your progress dialog.

Btw, why do you use SHFileOperation instead of the operations provided by QDir and QFile?

like image 147
Ton van den Heuvel Avatar answered Oct 22 '25 04:10

Ton van den Heuvel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!