How to open a new window from the main window in Qt?

I am new to qt programming and would like to know how to open a new window from the main window with mainwindow disappearing? Is there any source code that I can take a look at?

+4
source share
3 answers

From the slot in MainWindow, call this code:

QWidget *wdg = new QWidget; wdg->show(); hide();//this will disappear main window 
+5
source

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(); } 
+3
source

try this instead

 this-> hide(); 
0
source

Source: https://habr.com/ru/post/1494664/


All Articles