Reputation: 41
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
Upvotes: 4
Views: 2038
Reputation: 10528
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
?
Upvotes: 7