[Interest] The right way of using QProcess

Thiago Macieira thiago.macieira at intel.com
Tue May 19 16:58:32 CEST 2015


On Tuesday 19 May 2015 15:29:04 Nuno Santos wrote:
> Hi,
> 
> I’m calling the function below with a one second interval while my app is
> open. The functions executes the command “adb devices"
> 
> Is there any kind of limitation by the system by the number of calls? I
> think my system gets to a point where no more processes can be created:
> Chrome starts to hang, QtCreator isn’t able to do make, etc

Sounds like an attack of the zombies.... (no, really, there must be zombie 
process left around)

> 
> static QString executeAdbCommand(QStringList arguments)
> {
>     QProcess p;
> 
>     //p.setReadChannel(QProcess::StandardError);
> 
>     #ifdef Q_OS_MAC
>     p.start(QString("%1/adb").arg(QCoreApplication::applicationDirPath()),
> arguments); #endif
> 
>     #ifdef Q_OS_WIN
>     p.start("adb.exe", arguments);
>     #endif
> 
>     //qDebug() << "Executing adb" << arguments;
> 
>     if (!p.waitForStarted())
>        return "";
> 
>     if (!p.waitForFinished())
>        return "";
> 
>     QString output = p.readAll();
> 
>     return output;
> }

Don't return until waitForFinished() succeeds. That one guarantees wait() has 
happened on the process, so we know there is no zombie left.

Is this Qt 5.4? Or are you already trying the 5.5 beta? The way we do wait() 
has changed considerably in 5.5, so it might be worth testing the beta to see 
if the problem also happens.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list