Wait for key before exit in console app
Hello,
I've simple console application and cannot find solution how to wait for some key before exit from it. It's simple with getchar() or std::cin.ignore, but I want to do it with Qt, because for console communication I already use it:
Code:
int main() {
// ...
cout << "Press <ENTER> to exit." << endl;
forever {
if (!Line.isNull()) {
break;
}
}
return 0;
}
Code inside forever was taken from stackoverflow, but doesn't work for me. Qt 4.7.3
Do you know some other solutions?
Re: Wait for key before exit in console app
QSocketNotifier opened on stdin and an event loop to keep your program running until there is something to read in the descriptor monitored by the notifier.
Re: Wait for key before exit in console app
Nice idea, but I think overhead of another class and event loop is too much just only to wait for key press. I thought about something simpe. It seems in console it's better to stay with std:: ...
Thanks anyway!
Re: Wait for key before exit in console app
If you want simple then you have getchar()/getch() :)
Re: Wait for key before exit in console app
well, getch is non standard and not always available
Re: Wait for key before exit in console app