I'm now adding GUI to a project original written for console operation. I chosen Qt as the framework and now facing difficulty in handling close event of QProgressDialog.
Issue 1: I used QtConcurrent::run to fork a process for a long/heavy task, and a 'waiting' QProgressDialog (range of 0,0) to hint user for a long running process. The problem is I cannot have the dialog to close itself!
void MainWindow::doLongRunProcess() {
pDialog = new QProgressDialog("Loading 2 ...", "Abort", 0, 0, this);
pDialog->setWindowModality(Qt::WindowModal);
pDialog->show();
QFuture<void> future = QtConcurrent::run(theApp, &SimApplication::runSimulation);
QFutureWatcher<void> watcher;
connect(&watcher,
SIGNAL(finished()),
this,
SLOT(endLongRunProcess()));
watcher.setFuture(future);
// at this point, the runSimulation is successfully invoked
}
void MainWindow::endLongRunProcess()
{
// no sign of being invoked!
if (pDialog)
{
pDialog->close();
delete pDialog;
}
logMessage("Operation completed");
}
Requirement 1: If possible, don't want to touch/change the code of the original package.
Issue 2: How to link the "abort" button to terminate the SimApplication::runSimulation()?