PDA

View Full Version : How to wait for process to finish



roseicollis
22nd December 2014, 10:20
Hi,
I have the next call to run a scrip that unzip a zip:
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.


Thank you.

anda_skoa
22nd December 2014, 11:16
Don't use startDetached() but a real QProcess instance and connect to its signals.

Cheers,
_

roseicollis
22nd December 2014, 12:06
QProcess process;
And then how do you run the script? process.???

To connect it I suppose you mean to do something like:

connect(this, SIGNAL(process.finished()), this, SLOT(HasFinished());

declaring in the .h


private slots: HasFinished();

anda_skoa
22nd December 2014, 13:47
QProcess process;
And then how do you run the script? process.???

I recommend looking at the Qt documentation for QProcess.



To connect it I suppose you mean to do something like:

connect(this, SIGNAL(process.finished()), this, SLOT(HasFinished());

Yes, but with a sender that actually makes sense and a valid signal name.



declaring in the .h


private slots: HasFinished();
[/quote]
Right, but with actually correct syntax.

Cheers,
_

roseicollis
22nd December 2014, 15:17
Ok thank you :)

Edited: Implemented with process.start() and working :)