views:

147

answers:

2

I have an application which makes use of 20 different classes. The program execution starts in mainwindow. I start a progress dialog. I will make use of different classes for different purposes. After each function call which the execution goes to the particular class and does the required and come back to the mainwindow class, I will update the progress dialog. Now, the issue is the progress dialog freezes when the execution goes away from the mainwindow class. The cancel button is unable to accessed and so, the execution could not be stopped at the required time.

mainclass::mainclass() {

ProgressDialog->exec();

x->add();

updateProgressDialog();

y->do();

updateProgressDialog();

zz->bring();

updateProgressDialog();

}

// x, y, z are three different classes.

This is how the execution goes. As soon as I enter the function in the main class, I will start the progress dialog. and call functions from different classes. The functions take considerable amount of time. I have invoked a thread to do the execution part, but I am unable to cancel the progress diaolog. I want the program execution to be stopped as and when the cancel button is pressed on the proggress dialog.

Please let me know how to get away with this issue. Hope I am clear here.

+1  A: 

Without knowing exactly what calculations are being preformed in your threads its hard to isolate the problem. Maybe this can help: Keeping the GUI Responsive

Excerpt from: Performing Long Operations (by: Witold Wysota)
During long calculations (regardless of any usage of signals and slots) all event processing gets halted. As a result, the GUI is not refreshed, user input is not processed, network activity stops and timers don't fire—the application looks like it's frozen and, in fact, the part of it not related to the time-intensive task is frozen.

Adam
A: 

The functions you are calling are not processing the Qt events loop. You are using a modal progress bar, since you are calling exec(). This means that Qt only gets control at the times where you update the dialog.

The only way that I know of to work around this is to code the dialog as modeless, but you will also have to provide an opportunity for the events loop to process.

This is explained in a fair amount of detail in the Qt docs: QProgressDialog

Michael Mathews