PDA

View Full Version : Creating a timed menu in Main()



simy307
24th May 2013, 23:15
Using Qt5 and QCoreApplication I want to create a timed menu that waits 15 seconds for a response, and if one is not received, moves on to the eventloop and the rest of the program. This program is ran completely from the console. I have tried using a timed while loop, however


cin.readLine();

stops the loop and waits for a response.

Any ideas on how to go about creating this?

saman_artorious
25th May 2013, 09:20
Using Qt5 and QCoreApplication I want to create a timed menu that waits 15 seconds for a response, and if one is not received, moves on to the eventloop and the rest of the program. This program is ran completely from the console. I have tried using a timed while loop, however


cin.readLine();

stops the loop and waits for a response.

Any ideas on how to go about creating this?


!!! get a timer, with a flag set. if user inputs something readline returns with flag set to entered.
else, if timer passed with no input, then write dummy chars to get rid of readline.

wysota
25th May 2013, 09:34
Using Qt5 and QCoreApplication I want to create a timed menu that waits 15 seconds for a response, and if one is not received, moves on to the eventloop and the rest of the program. This program is ran completely from the console. I have tried using a timed while loop, however


cin.readLine();

stops the loop and waits for a response.

Any ideas on how to go about creating this?

Setup a QSocketNotifier on stdin, connect to its signal and run the event loop (e.g. via QEventLoop). Together with a timer that will quit the loop after 15 seconds, you can set a mechanism appropriate for your task.