title: QDialog exec() and getting result value
body: <p>I have subclassed <code>QDialog</code> to implement functionality similar to <code>QMessageBox</code> ( I needed this to allow for customization). It has a text message and OK, Cancel buttons. I am showing the dialog using <code>exec()</code> to make it blocking. Now, how do I return values of true/false when the user clicks on OK/Cancel?</p>
  
  <p>I tried connecting the buttons to <code>setResult()</code> and then, return the result value when clicked, but</p>
  
  <ol>
  <li>Clicking the buttons does not close the dialog box</li>
  <li>the return value is incorrect. 
  Following is the code I have written. I think I am wrong in the exec/result part - but I am not sure how to fix it.</li>
  </ol>
  
  <pre><code>class MyMessageBox : public QDialog {
      Q_OBJECT
  
  private slots:
  
      void onOKButtonClicked() { this-&gt;setResult(QDialog::Accepted); }
      void onCancelButtonClicked() { this-&gt;setResult(QDialog::Rejected); }
  
  public:
      MyMessageBox(QMessageBox::Icon icon, const QString&amp; title,
          const QString&amp; text, bool showCancelButton = true,
          QWidget* parent = 0);
  
      virtual void resizeEvent(QResizeEvent* e);
  
      QDialog::DialogCode showYourself()
      {
          this-&gt;setWindowModality(Qt::ApplicationModal);
          this-&gt;exec();
          return static_cast&lt;QDialog::DialogCode&gt;(this-&gt;result());
      }
  };
  </code></pre>
  
  <p>The user will instantiate the class and call <code>showYourself()</code> which is expected to return the value and also close(and delete) the dialog.</p>
  
  <p>I have posted partial code. Let me know if you need more and I will post the complete version.</p>