How can i check if QMainWindow is fully loaded ?



  • Hi
    in my application i like to invoke method only after the window on the QMainWindow is fully loaded ,
    how can i check this ? is there any onLoad callback/signal ? ( i checked and didn't found any thing )
    Thanks



  • You can realise this signal your self, and when in ctor all init emit your signal, then connect to slot and call your method.


  • Moderators

    What do you want to do with that signal?

    The UI is fully set up once the constructor of your mainwindow is done. It is save to just place all your custom code either into the constructor of your mainwindow class or right after the object is constructed.

    There is no delay to download images and code, etc. that you see when programming web apps, so on load behavior is not really that useful in a Qt UI in my experience.



  • but if i have some methods in my QMainWindow that are invoket after the ctor is invoket
    and its drawing some GUI element , how can i know that all the window is painted to the screen?



  • Tobias Hunger : i meant on finish load when windows is shown on screen , i have some http requests that i invoking on the window ctor , and its delay the window from showing in the screen



  • The window is show() on the screen after show is called.
    Another way is to derive and implement showEvent().



  • I think therfore is the polishEvent(). After this event the ui is fully constructed.



  • how can i use it ?



  • Reimplement the event method and check if the event is the polishEvent.
    @bool MainWindow::event(QEvent *event)
    {
    int returnValue = QWidget::event(event);

    if (event->type() == QEvent::Polish)
    {
    QSize widgetSize = this->size(); // store widget size
    return true;
    }

    return returnValue;
    }@



  • thanks for the answers



  • I had a similar problem and I used a QTimer::singleshot() with a timeout of 0 seconds. So my timer event was the first to fire after the app was in event loop (i.e. u can safely assume the app was loaded and was being displayed to the user ).



  • showEvent() is the right place to do these things.

    Don't forget to remember that you've initialized it in a bool member, otherwise you will re-initialize it every time your main window is shown again.

    Sample:

    @
    void yourMainWindow::showEvent( QShowEvent *event )
    {
    // call whatever your base class is!
    QDialog::showEvent( event );
    if( event->spontaneous() )
    return;

    if(isInitialized)
        return;
    
    // do your init stuff here
    
    isInitialized = true;
    

    }
    @

    Don't forget to set isInitialized to false in your constructor!



  • ok thanks for helping



  • [quote author="Volker" date="1307434864"]showEvent() is the right place to do these things.

    Don't forget to remember that you've initialized it in a bool member, otherwise you will re-initialize it every time your main window is shown again.

    Sample:

    @
    void yourMainWindow::showEvent( QShowEvent *event )
    {
    // call whatever your base class is!
    QDialog::showEvent( event );
    if( event->spontaneous() )
    return;

    if(isInitialized)
        return;
    
    // do your init stuff here
    
    isInitialized = true;
    

    }
    @

    Don't forget to set isInitialized to false in your constructor![/quote]

    I used code like this to ask the user if wants to load the last played song using a QMessageBox,
    but the question is shown before the main window. How could I know when the main window is completely visible?

    Tnxs!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.