Hi! I want to use a Qprogressbar using a For Loop. Every time the value inside the for loop changes, it sets the value of the progress bar. A sample code will be helpful.
Thanks!
Hi! I want to use a Qprogressbar using a For Loop. Every time the value inside the for loop changes, it sets the value of the progress bar. A sample code will be helpful.
Thanks!
Qt Code:
for(int i=0;i<100;++i) { progressBar->setValue(i); qApp->processEvents(); }To copy to clipboard, switch view to plain text mode
thanks wysota. regarding process events, i tried it now, but it seems the process becomes slow. is there a way to adjust the process time? the process im doing is transferring of files.
Thanks!
Obviously as your application has much more to do.
e.g.is there a way to adjust the process time? the process im doing is transferring of files.
Qt Code:
for(int i=0;i<100;++i) { progressBar->setValue(i); if(i % 100 == 0) qApp->processEvents(); }To copy to clipboard, switch view to plain text mode
my concern is that i want to prevent the application to get into "not responding" status if seen at the task manager while doing the for loop. i'll try your suggestion.thanks!
You can always copy files in a secondary thread, e.g. something like this might work:
Qt Code:
struct FileStruct { QString sourcePath; QString destPath; FileStruct(s, d) : sourcePath(s), destPath(d) {} }; bool copyFile(FileStruct s) { return true; } QList<FileStruct> filesToCopy; filesToCopy << FileStruct(...,...) << FileStruct(...,...) << FileStruct(...,...); QFuture<bool> result = QtConcurrent::mapped(filesToCopy, copyFile);To copy to clipboard, switch view to plain text mode
but it will probably be slower than copying one file at a time (unless you have a SSD disk).
Bookmarks