[Qt-interest] Waiting for QProcess to finish without freezing GUI
Lars Amsel
lars.amsel at signalion.com
Thu Jul 9 23:40:56 CEST 2009
Kyle,
qzvjtml02 at sneakemail.com wrote:
> QProcess::waitForFinish(). I know there's a better way to do this...
> does anyone have any advice? Ideally I'd display a "logging in"
> QProgressDialog while the console application runs. If the user clicks
> the "cancel" button on the QProgressDialog, I kill the QProcess. Is this
> possible without the GUI freezing?
Connect to the finished slot of the process, to get informed when the process is
killed or exits normally. Connect to the clicked of your cancel button. Start
your process like this:
QProcess* process = new QProcess();
connect(
process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, Slot(onProcessFinished(int, QProcess::ExitStatus)));
process->start("command to be executed");
//here you may show your dialog
The finished could be something like:
void MyClass::onProcessFinished(int exitCode, QProcess::ExitStatus status) {
delete process;
process = NULL;
qDebug() << exitCode << "\t" << status;
//hide the dialog
}
The cancel could look like:
void MyClass::onBtnCancelClicked() {
if (process != NULL) {
process->kill();
}
}
This should do the trick.
regards
Lars
More information about the Qt-interest-old
mailing list