Bruno1993
24th June 2015, 02:18
Hello, i have a problem in my application.
I'm programming an app with several forms; for example:
i have the class "MainWindow" and "Find_Patient" so i have this files:
MainWindow.cpp
MainWindow.h
MainWindow.ui
Find_Patient.cpp
Find_Patient.h
Find_Patient.ui.
Suppose that in MainWindow i have a button, and when i click that button, Find_Patient shows up and MainWindow dissapears.
so this is the code for that:
void MainWindow::on_open_find_patient_clicked()
{
Find_Patient *go = new Find_Patient
go->show(); //this is going bring up Find_Patient
this.hide(); //this is going to hide MainWindow
}
and this is the code for the button on Find_Patient.cpp to back to MainWindow
void Find_Patient::on_open_MainWindow_clicked()
{
MainWindow *back = new MainWindow
back->show(); //this is going bring up MainWindow
this.hide(); //this is going to hide Find_Patient
}
This code is totally functional, but it is not efficient.
Here's my problem:
Every time that i will click one of those buttons, the code will create a new object of type MainWindow or Find_Patient.
Doing this, it will ocupate a peace of memory every time that i click that button, because the previous object is hidden, not destroyed.
So my question is how i pass through forms?
This is the right way for doing it? or there is another way?.
i'm thinking on doing this:
MainWindow *back = new MainWindow
back->show(); //this is going bring up MainWindow
this.deleteLater(); //this is going to delete Find_Patient
but i don't know if this is correct.
Sorry my bad english, im spanish.
Thanks!
I'm programming an app with several forms; for example:
i have the class "MainWindow" and "Find_Patient" so i have this files:
MainWindow.cpp
MainWindow.h
MainWindow.ui
Find_Patient.cpp
Find_Patient.h
Find_Patient.ui.
Suppose that in MainWindow i have a button, and when i click that button, Find_Patient shows up and MainWindow dissapears.
so this is the code for that:
void MainWindow::on_open_find_patient_clicked()
{
Find_Patient *go = new Find_Patient
go->show(); //this is going bring up Find_Patient
this.hide(); //this is going to hide MainWindow
}
and this is the code for the button on Find_Patient.cpp to back to MainWindow
void Find_Patient::on_open_MainWindow_clicked()
{
MainWindow *back = new MainWindow
back->show(); //this is going bring up MainWindow
this.hide(); //this is going to hide Find_Patient
}
This code is totally functional, but it is not efficient.
Here's my problem:
Every time that i will click one of those buttons, the code will create a new object of type MainWindow or Find_Patient.
Doing this, it will ocupate a peace of memory every time that i click that button, because the previous object is hidden, not destroyed.
So my question is how i pass through forms?
This is the right way for doing it? or there is another way?.
i'm thinking on doing this:
MainWindow *back = new MainWindow
back->show(); //this is going bring up MainWindow
this.deleteLater(); //this is going to delete Find_Patient
but i don't know if this is correct.
Sorry my bad english, im spanish.
Thanks!