tags:

views:

76

answers:

4

Hi, 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

+5  A: 

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?

Ton van den Heuvel
A: 

Have you considered using QProgessDialog?

Roku
A: 

Hello, thanks a lot for your explanation and a possible solution! Really, it helped me a lot!!!

Oh, and I use SHFileOperation instead of QDir / QFile because some users of my program said my copy function is slow and the Windows Explorer is much faster on this operation. So I use the used a windows standard function hoping it will be a bit faster. At least I can say I use more or less the same functions as MS (some kind of psychology thing ;) ).

Thanks again!

BearHead
This should probably be a comment to the answer (or answers) instead of an answer itself. (The -1 was from me, and accidental, but now SO won't let me remove it.)
Caleb Huitt - cjhuitt
A: 

Yes, I considered using QProgressDialog. But I do not like the styling of the dialog and it doesn't match in this programming topic.

BearHead