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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...