Qt how to capture an event indicating that all gui elements are ready

I am 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 cannot be done in the window constructor. And they work great in the implementation of the slot.

For example, when I want to access the root window of my application, I do it like this

// in *.h MainWindow* rootWindow // in *.cpp rootWindow = qobject_cast<MainWindow *>(this->window()); 

If this is done in contructor, I cannot use the rootWindow object - this is a couses runtime error.

There is no corresponding slot for implementation. And creating an event in the QMainWindow class is not virtual.

Thanks for the help:)

+6
c ++ events qt qt4
source share
2 answers

To do this, you can use a timer with one shot. In your main window class, define a slot function called say, appReady() . In the constructor, create and connect a timer with a single timer using QTimer::singleShot(0, this, SLOT(appReady())); . This timer should be triggered as soon as the event loop is started and the incomplete start of events is started.

+9
source share

How can you be sure that the root window is actually MainWindow? Later, during the project life cycle, you could serve your widget to another parent (for example, several layers of QFrame decorations for layout purposes), and this code will not work.

Pass it as an explicit parameter in the constructor.

Until this is MainWindows to the end :)

0
source share

All Articles