[Interest] How to avoid QProcess polling

Joerg Bornemann joerg.bornemann at theqtcompany.com
Wed Apr 8 12:48:15 CEST 2015


On 08-Apr-15 09:21, Shantanu Tushar wrote:

> Lets say I launch an external application on Windows using this code-
[...polling in QProcess...]

This polling code is there for historical reasons. It's a naive way to 
simulate a socket notifier for stdin. If there's no data to write the 
_q_notified call doesn't do much.

> Right now I hack around this by doing this-
>
> QThread t;
> QProcess p;
> p.moveToThread(&t);
> p.start("C:\\Windows\\notepad.exe");
>
> which basically causes the hasEventDispatcher() if condition to false
> and no polling happens. However, this generates warnings because the
> QProcess attempts to generate children. Further, I lose the ability to
> read stdout from the process.

That's a bad way to avoid the polling for reasons you already mentioned.

> Is there a cleaner way to disable the polling? Or at least make it less
> frequent? Just in case you're wondering, this is important because our
> users are freaks about CPU utilization and they don't want to see >0%
> CPU usage when the app is idle from their perspective.

There's currently no way to disable the polling without changing Qt.
You can change the NOTIFYTIMEOUT define to a higher number and rebuild 
Qt to make the polling less frequent.
You might want to create a bug report with a justification why this 
issue is bad for you (apart from the fact that the current solution is 
inelegant).


BR,

Joerg



More information about the Interest mailing list