For example, a Q & A GameProgramThe program will continue to ask the next question only after entering the answer to the current question,
The input answer is manipulated by players, and the program must monitor the input at any time.
This problem can be easily solved in the console, and it must be solved by threads in qt gui applications,
# Include <windows. h> </P> <p> //...... <SPAN class = 'wp _ keywordlink '> Code </span> omitted <br/> while (! Issend) // issend is the validation variable for the input answer <br/>{< br/> qcoreapplication: processevents (); // UI refresh supported <br/> sleep (300); // The current thread sleeps for a period of time (0.3 s ), avoid occupying CPU all the time <br/>}// if you are sure to enter the answer, that is, if issend is true, the loop is displayed. <br/> issend = false; <br/> // action generated based on the current problem <br/> //... if you want to continue to raise questions, you can continue the cycle <br/>
Sync blog:Http://moxiaomomo.iteye.com/blog/1066709