Hi everyone,

I'm building a gui that creates a mainwindow in which there are two toolbar icons, when you click on any of them a certain dialog should appear. I have done this but it is crashing because it's not closing one widget when the other one opens. I was wondering if there is a command that will clear the CentralWidget, so that the new dialog may open without crashing. Here's my code:

Qt Code:
  1. void MainWindow::dialog1()
  2. {
  3. if (!dialog) {
  4. dialog = new Dialog1;
  5. }
  6. this->setCentralWidget( dialog );
  7. dialog->show();
  8. }
  9.  
  10.  
  11. void MainWindow::dialog2()
  12. {
  13. if (!dialog2) {
  14. dialog2 = new Dialog2;
  15. }
  16. this->setCentralWidget( dialog2 );
  17. dialog2->show();
  18. }
To copy to clipboard, switch view to plain text mode