title: Qt - What is the correct way to pause execution of a program to wait for user input?
body: <p>I have a program that runs through a series of steps where the user selects points on a displayed picture. I am unsure of the proper way to pause execution while the user selects these points. Currently I am using something like this:</p>
  
  <pre><code>while(m_MouseCount &lt; 2)
  {
      qApp-&gt;processEvents(QEventLoop::WaitForMoreEvents);
      if(m_cancelFlag){
          // disconnect mousePressSignal
          return;
      }
  }
  </code></pre>
  
  <p><strong>The problem that I am running into is that when the window is closed during this loop, the program continues to run in the background.</strong></p>
  
  <p>It was brought to my attention that a Finite State Machine would be more appropriate to use in this case, and what I have done here is "horrible pseudo-synchronous" programming. But if I did use a FSM, I would still have the problem of waiting for the FSM to run its course before moving on to the next user selected measurement.</p>
  
  <p>Is there a better way to wait for user input?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I understand that the Qt's UI is event driven and doesn't generally pause. My program works as follows:</p>
  
  <ol>
  <li>The user is shown a picture and presented with a few options via pushbuttons (Crop, Start Analysis, Cancel)</li>
  <li>User Selects Crop</li>
  <li>User is prompted to select a rectangle to crop picture (until rectangle is selected program is "paused" - cancel option still exists)</li>
  <li>User selects Full Analysis</li>
  <li>User is prompted to select measurement 1.</li>
  <li>Program "pauses" until two points are selected.</li>
  <li>User is prompted to select measurement 2.</li>
  <li>Program "pauses" until two points are selected.</li>
  <li>This repeats until all measurements have been selected.</li>
  <li>Calculations are done based on measurements.</li>
  </ol>
  
  <p>I don't see anyway around some sort of pausing or waiting.</p>