Results 1 to 2 of 2

Thread: Delay in Between loading windows In Qt

  1. #1
    Join Date
    May 2011
    Posts
    16
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default Delay in Between loading windows In Qt

    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




    Qt Code:
    1. void startWindow::on_english_clicked()
    2. {
    3.  
    4.  
    5. MainWindow *other = new MainWindow;
    6. other->ui->tester->hide();
    7. other->ui->textBrowser->hide();
    8. other->ui->frame_2->hide();
    9. other->show();
    10. this->hide();
    11. }
    To copy to clipboard, switch view to plain text mode 
    this is the code in Loading the mainwindow and below is code that is redirected again to the startwindow ..


    Qt Code:
    1. void MainWindow::on_backward_clicked()
    2. {
    3. videoplayer->stop();
    4. videoplayer->hide();
    5. startWindow *start=new startWindow;
    6. start->show();
    7. this->close();
    8. this->deleteLater();
    9.  
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Delay in Between loading windows In Qt

    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:
    Qt Code:
    1. startWindow::startWindow( QWidget * parent ) : ...
    2. {
    3. ...
    4. this->_mainWindow = new MainWindow; // create and store mainWindow object
    5. this->_mainWindow->setStartWindow( this ); // here you can pass a pointer to this object
    6. // in order to show this window later
    7. }
    8.  
    9. // you can keep startWindow pointer as a member in mainWindow class
    10. void MainWindow::setStartWindow( startWindow * s ){
    11. this->_startWindow = s;
    12. }
    13.  
    14. // now your methods looks simpler
    15. void startWindow::on_english_clicked()
    16. {
    17. // MainWindow *other = new MainWindow; // no need to create new object each time
    18. _mainWindow->ui->tester->hide();
    19. _mainWindow->ui->textBrowser->hide();
    20. _mainWindow->ui->frame_2->hide();
    21. _mainWindow->show();
    22. this->hide();
    23. }
    24.  
    25. void MainWindow::on_backward_clicked()
    26. {
    27. videoplayer->stop();
    28. videoplayer->hide();
    29. // startWindow *start=new startWindow;
    30. this->_startWindow->show();
    31. this->close();
    32. }
    To copy to clipboard, switch view to plain text mode 
    This way you can avoid creating new widgets each time.

Similar Threads

  1. Loading Qt resource file on to Shared Memory Windows CE 5.0
    By thanuj in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 23rd December 2010, 12:34
  2. Delay DLL loading ?
    By black_coder in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2009, 00:00
  3. Replies: 3
    Last Post: 11th November 2009, 14:24
  4. Problems with loading ui files on windows
    By tyrdal in forum Qt Programming
    Replies: 2
    Last Post: 5th August 2009, 11:42
  5. Delay in loading qt widgets
    By pinakis in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2009, 06:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.