I've just started tinkering with QDialog and so just wanted to create one with a button saying "OK" there. The code's the following:

Qt Code:
  1. bool MyCanvas::HorizonDialog()
  2. {
  3. QDialog* dlg = new QDialog(this);
  4. dlg->setAttribute(Qt::WA_DeleteOnClose);
  5. QHBoxLayout layout;
  6. QPushButton ok("OK",dlg);
  7. ok.setDefault(true);
  8. connect(&ok,SIGNAL(clicked()),dlg,SLOT(close()));
  9. layout.addWidget(&ok);
  10. dlg->setLayout(&layout);
  11. dlg->raise();
  12. dlg->show();
  13. return true;
  14. }
To copy to clipboard, switch view to plain text mode 

I want the dialog to be modeless, so I chose to use QDialog::show() instead of ::exec(). However, when I run the program, the pushbutton doesn't appear. Should I use QDialog::exec(), however, the button does appear and everything works fine. I've tried "ok.show()" both before and after "dlg->show()" and neither worked.

Help?