borisbn

QSocketNotifier doesn't work with std::cin

Aug 23rd, 2012
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //main.cpp
  2. #include <QCoreApplication>
  3. #include <QSocketNotifier>
  4. #include <stdio.h>
  5. #include "obj.h"
  6. #include <iostream>
  7. int main( int argc, char *argv[] )
  8. {
  9.     QCoreApplication a( argc, argv );
  10.     QSocketNotifier notifier( STDIN_FILENO, QSocketNotifier::Read );
  11.     Obj o;
  12.     QObject::connect( &notifier, SIGNAL( activated(int) ), &o, SLOT( onReadyRead(int) ) );
  13.     std::cout << ">>";
  14.     return a.exec();
  15. }
  16. // obj.cpp
  17. void Obj::onReadyRead(int)
  18. {
  19.     std::string command;
  20.     std::cin >> command;
  21.     std::cout << std::endl << "command is: " << command << std::endl << ">>";
  22. }
Advertisement
Add Comment
Please, Sign In to add comment