PDA

View Full Version : QProgressDialogButton is not responding



gowen
14th August 2011, 18:36
Hello

I am having a problem using QProgressDialog.

The problem I am having is that when I try to get QProgressDialog to run with a cancel option, I cannot click the button and therefore it will not exit the calculation operation.

I have done some digging around and I have seen that if a complex calculation is going on, then this could be the reason. However, this calculation is running in its own seperate thread and I would have thought would have therefore been 'de-coupled' from the main GUI.

At the moment QProgressDialog is being called from the thread doing the calculation and in an effort to try and de-couple it further, I have made a custom QProgressDialog class which is its own seperate thread. Although this still doesnt seem to work.

Would I need to make the QProgressDialog a child of the main GUI and keep the calculations processing in its own thread?

I am at a bit of a loss at what to really do....

Many Thanks
Geoff

stampede
14th August 2011, 19:13
At the moment QProgressDialog is being called from the thread doing the calculation
You cannot use QtGui components (like widgets) in thread other than main GUI thread. Implement communication with the worker thread using signals and slots - create a subclass of QObject to perform calculations and give it "void progress(int)" signal to indicate progress of calculation. Next, connect this signal to setValue(int) slot in QProgressDialog with Qt::QueuedConnection. In order to pause calculations, create a "void pause()" slot in this worker class and connect void QProgressDialog::canceled () to it. Then create QThread object, start it and moveToThread() your object which performs calculations.