Hello,

Im making a console application where Im getting user input with std::getline() (in a while loop). Im also using QextSerialPort (inherits QIODevice) and readyRead() signal. Thus I need an event loop so I'm using QCoreApplication and calling a.exec().

The problem is getline() blocks event loop and, while it's blocked, I can't receive anything from serial port. I tried to use QCoreApplication:rocessEvents() in the while(1){getline()} loop, but found that's not a good solution. Then, I tried to call QCoreApplication:rocessEvents() in a QThread but it didn't work.

Here's the code Im using:

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QCoreApplication a(argc, argv);
  4.  
  5. Base *base = new Base();
  6. Commander *commander = new Commander(base);
  7.  
  8. QObject::connect(commander, SIGNAL(end()), &a, SLOT(quit()));
  9. QTimer::singleShot(0, commander, SLOT(run()));
  10.  
  11. return a.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void Commander::askToConnect()
  2. {
  3. if(base->connect() == false){
  4. cout << "Failed to open port." << endl;
  5. }
  6. }
  7.  
  8. void Commander::run{
  9. string inputline;
  10.  
  11. askToConnect();
  12.  
  13. while(1){
  14. QCoreApplication::processEvents(); // ???
  15.  
  16. cout << endl << "> ";
  17. getline(cin, inputline);
  18.  
  19. // ...
  20. }
  21. }
To copy to clipboard, switch view to plain text mode 

Even if I have while(1); the event loop is blocked and I can't read data from serial port.

So, how can I get user input without blocking event loop?

Thanks!