[Solved] How to wait for process to finish
-
Hi,
I have the next call to run a scrip that unzip a zip:
@
//MainWindow.cpp
process.startDetached("/bin/sh", QStringList()<< "/home/sg/Docs/MyScript.sh" << Arg1);
@Once its unzipped, I want to make things with those files. The problem is that it seems that when I look for the files it says that they doen't exist (But they are in the folder and are readable and all ok).
It seems that its because the process hasn't finished yet unzipping because if i put a sleep(3) it works perfect. So my question is: how can I know when has process finished? I can't use a sleep cause its a gui aplicattion working on background.I've tried to use the connect() but the program never goes to processFinished();
private slots:
void processFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
QProcess *process;@
@
//MainWindow.cpp
//Constructor
{ connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)),this, SLOT(processFinished(int, QProcess::ExitStatus)));
[...]
process.startDetached("/bin/sh", QStringList()<< "/home/sg/Docs/MyScript.sh" << Arg1);
}void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
qDebug() << "Hii";
}
@Thank you.
-
Hi,
It's because you are calling startDetached (which by the way is a static function).
Just call start and you should see your slot getting called when the process is done.
-
Wow! Finally a problem with an easy answer! :D haha i had start and changed it into stardetached dunno why... I think I should check the difference between them :D
Thank you!