[Interest] How to avoid QProcess polling

Shantanu Tushar shaan7in at gmail.com
Wed Apr 8 09:21:51 CEST 2015


Hi,

Lets say I launch an external application on Windows using this code-

QProcess p;
p.start("C:\\Windows\\notepad.exe");

Once I run the app and notepad (in this example) is launched, there is
constant activity happening in my main process (which I found using
http://technet.microsoft.com/en-in/sysinternals/bb896653.aspx).

I used some profiling tools and found that its because of a QTimer that
QProcess starts here-

    if (threadData->hasEventDispatcher()) {
        processFinishedNotifier = new QWinEventNotifier(pid->hProcess, q);
        QObject::connect(processFinishedNotifier,
SIGNAL(activated(HANDLE)), q, SLOT(_q_processDied()));
        processFinishedNotifier->setEnabled(true);
        notifier = new QTimer(q);
        QObject::connect(notifier, SIGNAL(timeout()), q,
SLOT(_q_notified()));
        notifier->start(NOTIFYTIMEOUT);
    }

(from
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qprocess_win.cpp#n542
)

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.

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.

Thanks,

-- 
Shantanu Tushar    (UTC +0530)
shantanu.io
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150408/4877cea7/attachment.html>


More information about the Interest mailing list