On 05/04/2018 10:26 PM, [email protected] 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?

Why do people attempt to do any form of IO in the main event loop? I realize there are a rash of really horrible examples out there, in particular EVERY database example officially published, but come on, thread it off and have the thread fire signals after IO has occurred. No need to involve a socket. If you really want to get fancy you can have that thread use something like the select option shown near the bottom of this page.

https://stackoverflow.com/questions/6171132/non-blocking-console-input-c

Someone tried, and mostly failed, with a ConsoleReader class for Qt here:

https://stackoverflow.com/questions/6878507/using-qsocketnotifier-to-select-on-a-char-device/7389622#7389622

And you can always resort to polling if you wish to believe input won't overrun any OS level input buffer.

http://www.coldestgame.com/site/blog/cybertron/non-blocking-reading-stdin-c

Btw, the existing database examples (&()*&)*(ed me off so much I wrote this book:

http://www.theminimumyouneedtoknow.com/qt_book.html

--
Roland Hughes, President
Logikal Solutions
(630)-205-1593

http://www.theminimumyouneedtoknow.com
http://www.infiniteexposure.net
http://www.johnsmith-book.com
http://www.logikalblog.com
http://www.interestingauthors.com/blog
http://lesedi.us/
http://onedollarcontentstore.com

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to