Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

c++ - How to get QIODevice-like signals for console input (stdin)?

I'm writing console app, based QCoreApplication, and I want to get signals, when user input something into stdin (whole line at once or by characters, it is not important for my app).

QFile not emit signals according to documentation, so any ideas how to get signal if user put in something to stdin?

At now I'm working with qt 4.8.7/linux/amd64, but I want port this code to macosx and windows in the future.

Update

I found solution that should work on *nix based OS, like linux and mac os x:

https://gist.github.com/gjorquera/2576569

But what about windows, would it also with with QSocketNotfier?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Unix (Linux, OS X), this answer has a solution.

For Windows, you cannot use QSocketNotifier: instead, use a QWinEventNotifier on the console handle you obtain from GetStdHandle (see this answer). The code will be almost identical to the Unix variant from the answer above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...