0

I was reading around, and I got the impression (correct me if I am wrong) that keypress events work only for gui applications, and the only thing a commandline will detect is a carriage return (/n). I have a command line application, and am looking to implement this basic logic:

if (programHasError) {
    qDebug() << "Error: Your program has generated an error. Press return to quit";
    QEventLoop haltProgram;
    connect(foo,SIGNAL(pressReturn()), haltProgram, SLOT(quit()));
    haltProgram.exec();
    a.quit(); // quits commandline application.
}

How can I achieve this?

Anon
  • 2,267
  • 3
  • 34
  • 51
  • 1
    Why do you want to start event loop? You can simply request for any button without event loop: `qDebug() << "Error: Your program has generated an error. Press any key to quit";` `getch();` – Vladimir Bershov Dec 27 '16 at 20:10
  • @VladimirBershov `haltProgram.exec();` starts the event loop. I'll look into `getch();` though; Thanks. – Anon Dec 27 '16 at 20:12
  • @VladimirBershov I can't figure out the `#include` for getch. `conio.h` doesn't seem to be on my system (Linux)? – Anon Dec 27 '16 at 20:22
  • 1
    here is a solution: http://stackoverflow.com/a/23035044/4149835 – Vladimir Bershov Dec 27 '16 at 20:30

0 Answers0