I'm building a Qt windows application that needs to react to data being written to its stdin. I realise I could use blocking threads or polling timers here, but it seems like this should be doable using QWinEventNotifier.
However, if I initialise a notifier as notifier_ = new QWinEventNotifier(GetStdHandle(STD_INPUT_HANDLE));
, this notifier seems to emit activated
constantly, regardless of whether or not there is any data available to be read.
What am I missing? Do I need to manually reset the event somehow? Is there a different handle I should be using?
The consequence here is that when I then try to read from stdin when this signal is emitted, the calls block forever - the stdin stream is still open, but not enough data is available to be read, so the calls don't return until more is written. Does Qt provide any tools that would let me avoid getting stuck like this without resorting to messily terminating threads?