using QTextStream to read stdin in a non-blocking fashion

♀尐吖头ヾ 提交于 2019-11-30 19:21:37

Line buffering.

Default is flushing after a "\n". If you write 5 lines to your process, your slot gets called 5 times. If you want to avoid that, you have to call setbuf(stdin, _IOFBF). But even then it is not guaranteed you can read arbitrarily large amounts of data in one chunk.

Edit: It would probably better to use QTextStream::atEnd() instead of select, since QTextStream has its own internal buffers.

kikeenrique

I've found and example in other answer that fits almost to this question and with complete and simple code:

https://stackoverflow.com/a/7389622/721929

I've used it to implement a QT console based app with a textual menu to choose on user selection.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!