This is what I wanted to do: a MainWindow launcher screen which, from a pushButton click event, goes hidden, shows MainWindow2, then when MainWindow2 is closed, is visible again.
This is what I expected to do:
void MainWindow::on_pushButton_clicked()
{
MainWindow2 *w = new MainWindow2(this);
connect(w, SIGNAL(destroyed()), this, SLOT(show()));
this->hide();
w->show();
}
void MainWindow::on_pushButton_clicked()
{
MainWindow2 *w = new MainWindow2(this);
connect(w, SIGNAL(destroyed()), this, SLOT(show()));
this->hide();
w->show();
}
To copy to clipboard, switch view to plain text mode
Alas, closing MainWindow2 actually closes the entire application. I ended up having to override MainWindow2's closingEvent to do this:
{
if (this->parentWidget() != 0)
{
this->parentWidget()->show();
}
event->accept();
}
void MainWindow2::closeEvent(QCloseEvent *event)
{
if (this->parentWidget() != 0)
{
this->parentWidget()->show();
}
event->accept();
}
To copy to clipboard, switch view to plain text mode
This feels like a hack to me because logically I feel the application should never close as long as I never close the parent. Am I doing this wrong?
Bookmarks