1

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?

user3896248
  • 347
  • 1
  • 5
  • 16
  • See this https://stackoverflow.com/a/59348696/6622587 – eyllanesc Jul 27 '20 at 15:04
  • Thanks, I hadn't ran into that example - but, that example also seems to illustrate my problem. The notifier emits activated even when there's nothing to read, and the read call then blocks forever. – user3896248 Jul 27 '20 at 15:37
  • Blocks and hangs the UI, but not the console itself in my case too @user3896248. I will tell you if I find a solution. – Alan Kałuża Aug 02 '20 at 03:20

0 Answers0