title: How can I return to main in Qt?
body: <p>I've been working on a project recently which is a simple game. I've written the following code in my main function (file main.cpp):</p>
  
  <pre><code>    ending_note = "Draw.";
      End_Page end(ending_note, a);
      end.show();
      (*a).exec();
      if(end.flag == 1)
      {
          return 1;
      } //end if
  </code></pre>
  
  <p>where a is a Qapplication object. The class End_Page is defined as follows (file end_page.cpp):</p>
  
  <pre><code>End_Page::End_Page(string _winner, QApplication* _a, QWidget *parent):QWidget(parent){
  
  a = _a;
  this-&gt;setFixedSize(900, 675);
  this-&gt;move(350, 50);
  flag = 0;
  
  //------------------- background label
  background = new QLabel(this);
  QMovie* movie2 = new QMovie("..\\project\\Data\\pic\\7.jpeg");
  movie2-&gt;setScaledSize(QSize(this-&gt;width(), 600));
  background-&gt;setMovie(movie2);
  background-&gt;setGeometry(0, 0, this-&gt;width(), 600);
  movie2-&gt;start();
  
  //-------------------- set label
  QString s;
  label = new QLabel(s.fromStdString(_winner), this);
  label-&gt;setStyleSheet("QLabel { color : rgb(200, 0, 30); qproperty-alignment: AlignCenter; }");
  QFont f( "MV Boli", 32, QFont::Bold);
  label-&gt;setFont(f);
  label-&gt;setGeometry(0,this-&gt;height() - 400, this-&gt;width(), 160);
  
  question = new QLabel("Do you want to play again?\n", this);
  question-&gt;setStyleSheet("QLabel { color : black;}");
  question-&gt;setGeometry(375, 610, 200, 30);
  
  accept = new QPushButton("Yes", this);
  accept-&gt;setGeometry(300, 630, 80, 40);
  decline = new QPushButton("No", this);
  decline-&gt;setGeometry(500, 630, 80, 40);
  
  //-------------------- connect
  connect(this,SIGNAL(closeSignal()), this, SLOT(closeProgram()));
  connect(decline, SIGNAL(clicked()), this, SLOT(closeProgram()));
  connect(accept, SIGNAL(clicked()), this, SLOT(restartProgram()));
  </code></pre>
  
  <p>}</p>
  
  <pre><code>End_Page::~End_Page(){}
  
  void End_Page::closeEvent(QCloseEvent* event){
  emit closeSignal();
  event-&gt;accept();
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void End_Page::EndGame(){
  a-&gt;exit();
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void End_Page::closeProgram(){
  exit(0);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>void End_Page::restartProgram(){
  flag = 1;
  a-&gt;exit();    
  </code></pre>
  
  <p>}</p>
  
  <p>My problem is that, after the program executes the statement (*a).exec();, if the user click on the push button labeled Yes, the program executes the function restartProgram to the end, but after that it doesn't continue back in function main (in other words it gets stuck there). How can I solve this problem?</p>