Be careful!
Qt Code:
  1. {
  2. MyMainWindow w;
  3. ...
  4. w1.setCentralWidget(&w); // w1 becomes w's parent
  5. w1.show();
  6. } // (*)
To copy to clipboard, switch view to plain text mode 

(*) First "w1" goes out of scope and deletes its children, including "w". Then "w", which was already deleted by its parent ("w1"), goes out of scope => crash!