PDA

View Full Version : Delay in Between loading windows In Qt



vishnu717
5th July 2011, 08:18
Hello


I am Beginner to Qt


I used to navigate windows By creating object of that window and hiding the present window . But the Loading time is about 6 seconds . I wanted to get rid of this.
Here is My code of creating Object of Window







void startWindow::on_english_clicked()
{


MainWindow *other = new MainWindow;
other->ui->tester->hide();
other->ui->textBrowser->hide();
other->ui->frame_2->hide();
other->show();
this->hide();
}





this is the code in Loading the mainwindow and below is code that is redirected again to the startwindow ..




void MainWindow::on_backward_clicked()
{
videoplayer->stop();
videoplayer->hide();
startWindow *start=new startWindow;
start->show();
this->close();
this->deleteLater();


}

stampede
5th July 2011, 10:07
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();
}


This way you can avoid creating new widgets each time.