What have I done wrong here? What happens is that it just put the new widget on top on the old one. I have tried the update() function but it does not seem to do anything in this case. It works if I delete the widget but as I do not know what widget that is in the layout at the moment I have no idea how to destroy the widget as I can not delete widgets that is already deleted(program freezes)
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); startGui = new StartScreenGUI(); ui->verticalLayout->insertWidget(0,startGui); } void MainWindow::switchToStart() { deleteGuis(); startGui = new StartScreenGUI(); ui->verticalLayout->insertWidget(0,startGui); } void MainWindow::deleteGuis() { ui->verticalLayout->removeWidget(startGui); ui->verticalLayout->removeWidget(schemeGui); ui->verticalLayout->removeWidget(settingsGui); ui->verticalLayout->removeWidget(listGui); ui->verticalLayout->removeWidget(historyGui); }