I am at a lose here on how to achieve what I am trying to do in my current application. Basically what happens is that there is a custom QTreeView that when the user drags and drops and item onto another item, the underlying data is changed and it can take several minutes for the application to move all the data correctly. I am trying to use a QProgressBar to show the user that the data is being moved and that the program is still working just needs some time to process the information.
Here is the code that occurs when a dropEvent happens:
{
// doing some stuff
emit viewChanged()
}
void ClassA::dropEvent(QDropEvent *event)
{
// doing some stuff
emit viewChanged()
}
To copy to clipboard, switch view to plain text mode
MainWindow class handles the emitted changed like so...
connect(classA, SIGNAL(viewChanged()), this, SLOT(updateViewChanged()));
connect(classA, SIGNAL(viewChanged()), this, SLOT(updateViewChanged()));
To copy to clipboard, switch view to plain text mode
The corresponding slot makes some data changes and then a private function inside of this slot does a lot of heavy lifting.
void MainWindow::updateViewChanged()
{
// doing some stuff
// now making call to heavy lifting function
updateData()
}
void MainWindow::updateViewChanged()
{
// doing some stuff
// now making call to heavy lifting function
updateData()
}
To copy to clipboard, switch view to plain text mode
The updateData() function can take several minutes to update information and what it is doing is changing values in QHash tables and some QLists in order for the information to be written back to the corresponding files correctly. Inside this function there are several loops that are time consuming.
void MainWindow::updateData()
{
QProgress progress(this);
// set min/max appropriately with setMinimum(int) and setMaximum(int)
// set variable called counter to increment the value of progressBar
// nested loops
while()
{
progress.setValue(counter++);
for()
{
progress.setValue(counter++);
for()
{
progress.setValue(counter++);
}
}
}
void MainWindow::updateData()
{
QProgress progress(this);
// set min/max appropriately with setMinimum(int) and setMaximum(int)
// set variable called counter to increment the value of progressBar
// nested loops
while()
{
progress.setValue(counter++);
for()
{
progress.setValue(counter++);
for()
{
progress.setValue(counter++);
}
}
}
To copy to clipboard, switch view to plain text mode
Basically when this function is called everything happens as should but no progress bar is displayed and I have no clue why. If I add qApp->processEvents() under each progress.setValue() call then the operation takes forever and still no progress bar displayed.
Any suggestions or help would be appreciated because I am not sure how to accomplish what I want to happen. FYI, I know this would make QProgressDialog every time the function is called that won't be the end result but I am just trying to get the darn bar to show!
Thanks for any help!!
Bookmarks