
Originally Posted by
Zlatomir
Why do you call show() in your class constructor and not in the main function?
And on topic, it depends on what do you want to initialize, give more information.
I think this is the same:
int main(int argc, char *argv[])
{
MyWidget myWidget;
myWidget.show();
return a.exec();
}
MyWidget::MyWidget()
{
...
do_heavy_init();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget myWidget;
myWidget.show();
return a.exec();
}
MyWidget::MyWidget()
{
...
do_heavy_init();
}
To copy to clipboard, switch view to plain text mode
In do_heavy_init(), I detemine what content should be shown in the main window, before that, I can just show a loading symbol.

Originally Posted by
Lykurg
Even if you do your heavy init after the widget is shown it will be useless since then your gui is shown but frozen. So if you can put all the stuff in a thread it would be the best.
Yeah, it might freeze for a while. But what I want is to call do_heavy_init(); after myWidget is shown.
I just checked the QSplashScreen,
Can this ensure that myWidget is shown before do_heavy_init()? :
int main(int argc, char *argv[])
{
MyWidget myWidget;
myWidget.show();
a.processEvents();
myWidget.do_heavy_init();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget myWidget;
myWidget.show();
a.processEvents();
myWidget.do_heavy_init();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks