I'm wondering if it is possible to capture an event that is generated when all Qt objects are initialized and ready ?
It seems that some things can't be done in window's constructor. And they work fine in slot implementation.
For example, when I want to access root window of my application I do it like that
// in *.h
MainWindow* rootWindow
// in *.cpp
rootWindow = qobject_cast<MainWindow *>(this->window());
If it is done in the contructor I can't use rootWindow object - it couses runtime error.
There is no relevant slot to implement. And create event in QMainWindow class is not virtual.
Thanks for help :)
You can use a single-shot timer for this. In your main window class, define a slot function called say,
appReady()
. In the constructor, create and connect a single shot timer usingQTimer::singleShot(0, this, SLOT(appReady()));
This timer should fire as soon as the event loop is up and running and there are no more startup events pending.How can you be sure that root window is in fact MainWindow? Later in the project lifetime you could feed your widget to a different parent (for example a few layers of QFrame decorations for layouting purposes) and this code will fail.
Pass it in as an explicit parameter in the constructor instead.
Unless it is MainWindows all the way down :)