Have you tried not to create new / delete windows and just create once and later only hide / show them ?
I think you are creating a memory leak, because objects of class startWindow may not be deleted, you just hide() them and later you create new object without parent set. Imagine this sequence:
- open start window, click "english" (start window 1 hides)
- in mainWindow, click "backward" (start window 2 created)
- in start window 2, click "english" ( start window 2 hidden )
- continue with above steps ...
Looks like startWindows are created and hidden but never deleted, I can't be sure, maybe somewhere else you delete them.
If creating the widgets takes so much time, you can do that once, for example in startWindow constructor:
startWindow
::startWindow( QWidget * parent
) : ...
{
...
this->_mainWindow = new MainWindow; // create and store mainWindow object
this->_mainWindow->setStartWindow( this ); // here you can pass a pointer to this object
// in order to show this window later
}
// you can keep startWindow pointer as a member in mainWindow class
void MainWindow::setStartWindow( startWindow * s ){
this->_startWindow = s;
}
// now your methods looks simpler
void startWindow::on_english_clicked()
{
// MainWindow *other = new MainWindow; // no need to create new object each time
_mainWindow->ui->tester->hide();
_mainWindow->ui->textBrowser->hide();
_mainWindow->ui->frame_2->hide();
_mainWindow->show();
this->hide();
}
void MainWindow::on_backward_clicked()
{
videoplayer->stop();
videoplayer->hide();
// startWindow *start=new startWindow;
this->_startWindow->show();
this->close();
}
startWindow::startWindow( QWidget * parent ) : ...
{
...
this->_mainWindow = new MainWindow; // create and store mainWindow object
this->_mainWindow->setStartWindow( this ); // here you can pass a pointer to this object
// in order to show this window later
}
// you can keep startWindow pointer as a member in mainWindow class
void MainWindow::setStartWindow( startWindow * s ){
this->_startWindow = s;
}
// now your methods looks simpler
void startWindow::on_english_clicked()
{
// MainWindow *other = new MainWindow; // no need to create new object each time
_mainWindow->ui->tester->hide();
_mainWindow->ui->textBrowser->hide();
_mainWindow->ui->frame_2->hide();
_mainWindow->show();
this->hide();
}
void MainWindow::on_backward_clicked()
{
videoplayer->stop();
videoplayer->hide();
// startWindow *start=new startWindow;
this->_startWindow->show();
this->close();
}
To copy to clipboard, switch view to plain text mode
This way you can avoid creating new widgets each time.
Bookmarks