체인에 여러 개의 창을 만들려고합니다. 창 1은 창 2의 부모이고, 창 2는 창 3의 부모입니다. 하나의 창을 닫으면 모든 자식도 닫을 수 있습니다. 현재 최상위 창을 닫으면 다른 모든 창은 원하는대로 닫히지 만 창 2와 같이 닫으면 창 2가 닫히고 창 3은 닫히지 않습니다. 어떻게해야합니까? 당신의 도움을 주셔서 감사합니다!Qt : 부모/자식 체인의 여러 창, 부모가 자식을 닫지 않습니까?
main_window.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QPushButton* button = new QPushButton("Open 1", this);
connect(button, SIGNAL(clicked()), this, SLOT(on_button_clicked()));
}
void MainWindow::on_button_clicked() {
window1 *w = new window1(this);
w->show();
}
window1.cpp
window1::window1(QWidget *parent) : QWidget(parent)
{
this->setWindowFlags(Qt::Window); // in order to have a free-standing window
QPushButton* button = new QPushButton("Open 2", this);
connect(button, SIGNAL(clicked()), this, SLOT(on_button_clicked()));
}
void window1::on_button_clicked() {
window2 *w = new window2(this);
w->show();
}
window2.cpp
window2::window2(QWidget *parent) : QWidget(parent)
{
this->setWindowFlags(Qt::Window);
QLabel* label = new QLabel("Window 2", this);
}
그건 속임수였습니다! "w-> setAttribute (Qt :: WA_DeleteOnClose); 추가" 위에 mainwindow.cpp에서 일했다. 다행히 closeEvent를 다시 구현할 필요가 없었습니다. 감사! – ishmael
위젯이 기본적으로 닫힐 때 삭제되지 않았다는 것을 알지 못했습니다. 도움이됩니다. 여하튼, 윈도우의 속성을 PySide 윈도우의 WA_DeleteOnClose로 설정하면 분할 오류 문제가 해결되었습니다. 이제 그 이유를 알아 내야합니다. – lightalchemist