Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i check if QMainWindow is fully loaded ?
Forum Updated to NodeBB v4.3 + New Features

How can i check if QMainWindow is fully loaded ?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 8 Posters 32.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rokemoon
    wrote on last edited by
    #2

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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #3

      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.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #4

        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?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          umen242
          wrote on last edited by
          #5

          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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #6

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

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Scylla
              wrote on last edited by
              #7

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

              1 Reply Last reply
              0
              • U Offline
                U Offline
                umen242
                wrote on last edited by
                #8

                how can i use it ?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Scylla
                  wrote on last edited by
                  #9

                  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;
                  }@

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    umen242
                    wrote on last edited by
                    #10

                    thanks for the answers

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SeedOfLife
                      wrote on last edited by
                      #11

                      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 ).

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #12

                        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!

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • U Offline
                          U Offline
                          umen242
                          wrote on last edited by
                          #13

                          ok thanks for helping

                          1 Reply Last reply
                          0
                          • U Offline
                            U Offline
                            ulesQt
                            wrote on last edited by
                            #14

                            [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!!!

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved