Solved How can I show an other widget or dialog before mainwindow
-
Hi
I want to show a loading dialog before mainwindow in main.cpp.int main(int argc, char *argv[]) { QApplication a(argc, argv); PreparingForm form; form.exec(); CMainWindow w; w.Init(); w.FunctionsInit(); w.show(); return a.exec(); }
but it doesn't work
-
@Mihan
IfPreparingForm
is derived fromQDialog
then so far as I am aware the code you show should indeed show it before the main window. If not you could just test:QApplication a(argc, argv); PreparingForm form; form.show(); return a.exec();
Otherwise Google for
qt show dialog before main window
, there are many posts. -
Hi,
What exactly does not work ?
The code you show does this:
- show a dialog while blocking the execution since you called exec.
- once the dialog is closed, it will continue and show your main window.
-
I want to show a loading window, when initializing the main window, the loading window will receive the signals about steps and show corresponding text. After initializing, the loading window will be closed and the main window will be showed.
Now I'm confused that the loading window is showed only with frame after I change
exec()
toshow()
, seems that the window doesn'tupdate()
. -
@Mihan
Then that is called a modeless window, and you would search for:qt show modeless dialog before main window
.From say https://stackoverflow.com/questions/49339411/qt-non-modal-dialog-before-main-window-is-created you would come across https://doc.qt.io/qt-5/qsplashscreen.html:
A splash screen is a widget that is usually displayed when an application is being started. Splash screens are often used for applications that have long start up times (e.g. database or networking applications that take time to establish connections) to provide the user with feedback that the application is loading.
-
Thank you @JonB
QSplashScreen
is exactly what I need ! ! !