1

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?

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
user1244932
  • 7,352
  • 5
  • 46
  • 103
  • What else is your program doing while it's waiting for user input? Anything? – John Zwinck Apr 26 '16 at 10:06
  • @JohnZwinck It communicate via sockets with different services, so I want `async` solution based on signals/slots, because of it more simple to support then multithread code – user1244932 Apr 26 '16 at 10:16
  • 1
    According to this: http://www.qtcentre.org/archive/index.php/t-20357.html you can't use `QSocketNotifier` with `fileno(stdin)` on Windows. But take a look at this answer: http://stackoverflow.com/a/23164552/4323 – John Zwinck Apr 26 '16 at 10:20

1 Answers1

1

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.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313