How can i check if QMainWindow is fully loaded ?
-
wrote on 5 Jun 2011, 07:37 last edited by
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 -
wrote on 5 Jun 2011, 08:07 last edited by
You can realise this signal your self, and when in ctor all init emit your signal, then connect to slot and call your method.
-
wrote on 5 Jun 2011, 10:01 last edited by
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.
-
wrote on 5 Jun 2011, 10:05 last edited by
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? -
wrote on 5 Jun 2011, 10:07 last edited by
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
-
wrote on 5 Jun 2011, 11:47 last edited by
The window is show() on the screen after show is called.
Another way is to derive and implement showEvent(). -
wrote on 5 Jun 2011, 13:11 last edited by
I think therfore is the polishEvent(). After this event the ui is fully constructed.
-
wrote on 5 Jun 2011, 13:41 last edited by
how can i use it ?
-
wrote on 5 Jun 2011, 15:15 last edited by
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;
}@ -
wrote on 6 Jun 2011, 12:29 last edited by
thanks for the answers
-
wrote on 7 Jun 2011, 03:50 last edited by
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 ).
-
wrote on 7 Jun 2011, 08:21 last edited by
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!
-
wrote on 7 Jun 2011, 08:49 last edited by
ok thanks for helping
-
wrote on 20 Feb 2013, 22:35 last edited by
[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!!!