title: How to close only subwindow when use closeEvent for X button?
body: <p>I use method <code>closeEvent</code> for X button on the top right in the interface.</p>
  
  <p><a href="https://i.stack.imgur.com/LwrGN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LwrGN.png" alt="window"></a></p>
  
  <p>The requirements are: </p>
  
  <ul>
  <li>when I click "Close" -> both windows (Exit and MainWindow) will be closed.</li>
  <li>when I click "Cancel"-> only "Exit" windows will be closed, MainWindow still stays there. </li>
  </ul>
  
  <p>But when I click on "Cancel", both windows are closed -> how to solve this problem?</p>
  
  <p>How to move button "Cancel" in between "Save" and "Close"</p>
  
  <p><a href="https://i.stack.imgur.com/AibPL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AibPL.png" alt="dialog"></a></p>
  
  <p>This is my code</p>
  
  <p>myclass.h</p>
  
  <pre><code>class MyClass : public QWidget
  {
      Q_OBJECT
  
  public:
      MyClass(QcgDatabase* db, int hostid, QWidget *parent = 0);
      ~MyClass();
  
  public slots:
      void save_clicked();
  
  private:
      Ui::MyClass ui;
      QMessageBox* dialog = NULL;
      void closeEvent(QCloseEvent *bar);
  };
  </code></pre>
  
  <p>myclass.cpp</p>
  
  <pre><code>MyClass::MyClass(QcgDatabase * db, int hostid, QWidget *parent)
  : QWidget(parent)
  {
      ui.setupUi(this);
      .......
      .......
  }
  
  void MyClass::closeEvent(QCloseEvent *bar)
  {
      if (!dialog) {
          dialog = new QMessageBox(this);
      }
      dialog-&gt;setWindowModality(Qt::WindowModal);
      dialog-&gt;setWindowTitle(QLatin1String("Exit"));
      dialog-&gt;setText(QLatin1String("You have not saved data. Click \"Close\" to close the data table."));
      dialog-&gt;setStandardButtons(QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Close);
  
      int result = dialog-&gt;exec();
      if (result == QMessageBox::Save) {
          save_clicked();
      }
      else if (result == QMessageBox::Cancel) {
          dialog-&gt;close();
          return;
      }
      else if (result == QMessageBox::Close) {
          dialog-&gt;close();
      }
  
      bar-&gt;accept();
  }
  </code></pre>
  
  <p>Edit:</p>
  
  <p>ok, i fixed the problem with window: </p>
  
  <pre><code> else if (result == QMessageBox::Cancel) {
      bar-&gt;ignore();
      return;
   }
  </code></pre>
  
  <p>Please help me to swap position of buttons "Close" and "Cancel"!</p>