ibex
26th October 2010, 16:32
Hi,
I'm having occasional trouble with a QProgressDialog connected to a QFutureWatcher (Qt4.6.2, x11). For roughly one in five occasions where the QFuture calculation is almost instantaneous (but never when it takes several seconds or more), the dialog appears empty with no cancel button or progress bar and can't then be closed.
Using something like the following (the watcher and dialog can be reused for different calculations):
class MyClass {
QProgressDialog mProgress;
QFutureWatcher mWatcher;
};
MyClass::MyClass() {
connect(&mWatcher, SIGNAL(finished()), &mProgress, SLOT(reset()));
connect(&mWatcher, SIGNAL(progressValueChanged(int)), &mProgress, SLOT(setValue(int)));
connect(&mWatcher, SIGNAL(progressRangeChanged(int,int)), &mProgress, SLOT(setRange(int,int)));
connect(&mProgress, SIGNAL(canceled()), &mWatcher, SLOT(cancel()));
connect(&mWatcher, SIGNAL(canceled()), &mProgress, SLOT(cancel()));
}
void MyClass::calculate() {
mWatcher.setFuture(QtConcurrent::map(begin(), end(), Calculator()));
}
My initial thought was that the map completes before all connections to the watcher can be made. However I have tried connecting debugging printing slots to the QFutureWatcher and all appropriate signals are being sent and received in the appropriate order. mWatcher.isRunning() always returns true immediately after the setFuture() call.
One other possibility would be as the manual says:
Note that if you set a new maximum (using setMaximum() or setRange()) that equals your current value(), the dialog will not close regardless
However debug printing shows this is also not the case.
Any ideas would be gratefully received.
I'm having occasional trouble with a QProgressDialog connected to a QFutureWatcher (Qt4.6.2, x11). For roughly one in five occasions where the QFuture calculation is almost instantaneous (but never when it takes several seconds or more), the dialog appears empty with no cancel button or progress bar and can't then be closed.
Using something like the following (the watcher and dialog can be reused for different calculations):
class MyClass {
QProgressDialog mProgress;
QFutureWatcher mWatcher;
};
MyClass::MyClass() {
connect(&mWatcher, SIGNAL(finished()), &mProgress, SLOT(reset()));
connect(&mWatcher, SIGNAL(progressValueChanged(int)), &mProgress, SLOT(setValue(int)));
connect(&mWatcher, SIGNAL(progressRangeChanged(int,int)), &mProgress, SLOT(setRange(int,int)));
connect(&mProgress, SIGNAL(canceled()), &mWatcher, SLOT(cancel()));
connect(&mWatcher, SIGNAL(canceled()), &mProgress, SLOT(cancel()));
}
void MyClass::calculate() {
mWatcher.setFuture(QtConcurrent::map(begin(), end(), Calculator()));
}
My initial thought was that the map completes before all connections to the watcher can be made. However I have tried connecting debugging printing slots to the QFutureWatcher and all appropriate signals are being sent and received in the appropriate order. mWatcher.isRunning() always returns true immediately after the setFuture() call.
One other possibility would be as the manual says:
Note that if you set a new maximum (using setMaximum() or setRange()) that equals your current value(), the dialog will not close regardless
However debug printing shows this is also not the case.
Any ideas would be gratefully received.