项目作者: juangburgos

项目描述 :
Small class to listen to console input asynchronously
高级语言: C++
项目地址: git://github.com/juangburgos/QConsoleListener.git
创建时间: 2018-09-21T11:09:41Z
项目社区:https://github.com/juangburgos/QConsoleListener

开源协议:MIT License

下载


QConsoleListener

Small Qt library to handle console input asynchronously using signals and slots. Based on gjorquera’s snippet.

Usage

Add to project in *.pro file

  1. include($$PWD/src/qconsolelistener.pri)

Include the header #include <QConsoleListener> and connect to the QConsoleListener::newLine signal. For example:

  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include <QConsoleListener>
  4. int main(int argc, char *argv[])
  5. {
  6. QCoreApplication a(argc, argv);
  7. // listen to console input
  8. QConsoleListener console;
  9. QObject::connect(&console, &QConsoleListener::newLine,
  10. [&a](const QString &strNewLine) {
  11. qDebug() << "Echo :" << strNewLine;
  12. // quit
  13. if (strNewLine.compare("q", Qt::CaseInsensitive) == 0)
  14. {
  15. qDebug() << "Goodbye";
  16. a.quit();
  17. }
  18. });
  19. qDebug() << "Listening to console input:";
  20. return a.exec();
  21. }

References