In mainwindow.h
Declare an nw object of class NewWindow below
NewWindow *nw = new NewWindow();
(Suppose we open NewWindow as soon as button 1 is pressed on MainWindow)
Then in the on_pushButton_1_clicked() slot of the MainWindow class:
void MainWindow::on_pushButton_1_clicked(){ nw->show(); this->hide(); }
source share