I tried to use QProcess to run program B from program A. I want to know when program B finished so the program A could do something else.
In CentOS system, both program A and B are GUI programs:
in mainwindow.h:
private:
QProcess proc;
private slots:
void procFinished(int exitCode, QProcess::ExitStatus exitStatus);
void on_execBPushButton_clicked();
in mainwindow.cpp
void MainWindow:n_execBPushButton_clicked()
{
QStringList args;
args << "1";
connect(&proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished(int, QProcess::ExitStatus)));
proc.start("<path>/B", args);
proc.waitForFinished();
}
void MainWindow:rocFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
cout << "procFinished() is called" << endl;
}
These are the code to handle the QProcess. I found if I use proc.waitForFinish(), the program A could not refresh the GUI. I know that because after B is launched, I drag the B across A and leave the "trace" on A forever. If I delete this waitForFinsihed(), program A and B both are refreshing when they need.
Also, the "procFinished() is called" did not display after program B is terminated. Instead, the "... is called" display when program A is terminated. So, could anyone tell me what I did wrong?
Thanks in advance.
Bookmarks