console.h
1 #pragma once
2 
3 #include <QObject>
4 #include <QSocketNotifier>
5 #include <QTextStream>
6 
7 #include <unistd.h> //Provides STDIN_FILENO
8 
9 namespace Input
10 {
19  class Console : public QObject
20  {
21  Q_OBJECT
22  public:
23  explicit Console (QObject *parent = 0) :
24  QObject(parent),
25  notifier(STDIN_FILENO, QSocketNotifier::Read)
26  {
27  connect(&notifier, &QSocketNotifier::activated, this, &Console::text);
28  }
29 
30  signals:
31  void textReceived(QString message);
32 
33  public slots:
34  void text()
35  {
36  QTextStream qin(stdin);
37  QString line = qin.readLine();
38  emit textReceived(line);
39  }
40  private:
41  QSocketNotifier notifier;
42  };
43 
44 }
Definition: console.h:9