// start_form.cpp void start_Form::on_db_Button_clicked(){ this->hide(); var_main_window = new Main_Window(this); //var_main_window->setAttribute(Qt::WA_DeleteOnClose); connect (var_main_window, Main_Window::main_window_close, this, start_Form::show); var_main_window->show();}// main_window.cppvoid Main_Window::closeEvent(QCloseEvent *event) { event->accept(); emit main_window_close();}// main_window.hprotected: void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;signals: void main_window_close(); void edit_window_open();
// main_window.cppvoid Main_Window::on_edit_table_triggered(){ var_edit_window = new edit_Form(); //var_edit_window->setAttribute(Qt::WA_DeleteOnClose); connect (this, Main_Window::edit_window_open, var_edit_window, edit_Form::show); connect (var_edit_window, edit_Form::edit_window_close, this, Main_Window::show); emit edit_window_open();}
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;...void edit_Form::closeEvent(QCloseEvent *event){ event->accept(); emit edit_window_close();}
qApp->setQuitOnLastWindowClosed(false);
C++ (Qt)#include <QCloseEvent>
C++ (Qt)event->accept()
C++ (Qt)MyForm1 * form1 = var_main_window->findChild<MyForm1 *>();if (!form1) // создадим форму 1 если ее еще нет form1 = new MyForm1(var_main_window);if (!form1->isVisible()) form1->show();
var_start_form.setAttribute(Qt::WA_DeleteOnClose);...var_edit_window->setAttribute(Qt::WA_DeleteOnClose);...var_main_window->setAttribute(Qt::WA_DeleteOnClose);
// var_start_window создаётся в главном окне QMainWindow.var_start_window = new start_Form(); // 1-ый вариант. Работает.var_start_window = new start_Form(this); // 2-ой. Не работает.
C++ (Qt)var_start_window = new start_Form(this, Qt::Window);