PDA

View Full Version : A question about QProcess



franco.amato
2nd August 2011, 08:58
Hi to all,
I would execute many times ( let say 10 times ) the same shell-based program from my Qt-application.
So I know that I can use QProcess to achieve my needs.

I think to put in a loop the call to the external program passing every time a new argument.

My doubt is this: when the external program finish, the process get destroyed?
In brief, I have to create every time a new process or can I use always the same with different arguments?
Thankx.
Regards

mcosta
2nd August 2011, 09:22
Hi Franco,

you can reuse QProcess instance but you have to wait until each external program terminates.

Lykurg
2nd August 2011, 11:41
And please, don't use a loop. The magic word is Signal&Slots: QProcess::finished().

franco.amato
2nd August 2011, 18:08
And please, don't use a loop. The magic word is Signal&Slots: QProcess::finished() (http://doc.qt.nokia.com/latest/qprocess.html#finished).

Hi Lykurg,
thank you very much. So once the external process has finished I can call it again with a new argument right ( in my case a QStringList containing a list of mp3 files )? So the process is not destroyed once the external program has finished? I have to destroy it manually?

@mcosta: I didn't get you. Why I have to wait that each external program terminates to reuse the process?
I would reuse it once the last is finished.

So something like this is not correct?

QString program = "my.exe";
QStringList argument;
QProcess *myProcess = new QProcess(parent);

for ( int ix = 0; ix < 10; ix++ )
{
argument.clear();
argument << newargument;
myProcess->start(my.exe, argument);
}


Thank you very much.
Regards

Lykurg
2nd August 2011, 18:27
So once the external process has finished I can call it again with a new argument right ( in my case a QStringList containing a list of mp3 files )? That's right.

So the process is not destroyed once the external program has finished? Yes, your QProcess object will live on.
I have to destroy it manually?QProcess inherits QObject, so the same rules as for most of the other Qt-classes apply also. Also think about creating a QProcess object as a member of your corresponding class. Then you don't have to take care about deleting.

Lykurg