[Interest] Non-blocking console reads

Thiago Macieira thiago.macieira at intel.com
Sat May 5 08:19:17 CEST 2018


On sexta-feira, 4 de maio de 2018 11:47:21 PDT Jason H wrote:
> I'm trying to (however inelegantly) treat the console as socket. I've tried
> using bytesAvailable() and readAll() but bytesAvailable() is always 0, and
> readAll will block. I do have an event loop and polling is ok with me. I'd
> rather not read the bytes in onTimeout(), and rather have the function
> connected to readSocket() do the reading.
> 
> Any ideas?

On Unix systems, use a QSocketNotifier to be notified of new activity and use 
fcntl() to set stdin to non-blocking mode. Then you can read in on-blocking 
mode.

On Windows, you'll have to research yourself. I tried once and failed to find 
any way to be notified of activity on the pipes. QProcess has a separate 
thread that keeps trying to read in blocking mode.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center






More information about the Interest mailing list