I have a Qt application with this kind of main()...
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
... A sep
You can send a signal to your window before the exec()
call. This will place an entry in app
's signal queue.
When exec()
is running, the signal will be delivered and your window will know that the event loop is running.
A simple way would be to use QTimer::singleShot(0, &mainWin, SLOT(onEventLoopStarted()));
which connects to a custom slot of your window class.
Since emitted signals don't get lost when the event loop is not yet running, your thread may not necessarily need to know when your window is ready.
Your thread could start sending signals to the window right away but it will only receive signals from the window when the event loop is running.
You can do it in the following order:
QApplication app(argc, argv);
Mainwinwdow mainWin;
QThread yourThread;
//connect the signals from the thread to the mainWin here
mainWin.Init();
mainWin.show();
yourThread.start();
return app.exec();