How to preload QDialog before it is shown?

174 views Asked by At

I have a QT application, which creates a dialog which has a bunch of tab pages, which each have a lot of Widgets.

I know there isn't going to be a way to get around how long it takes to load the widgets in as there are quite a few.

I've thought about after the main window being initialized, if there is something I can do to load the dialog in the background, so when show is clicked it is a faster experience.

Are there any techniques to preload dialogs, perhaps after the main window has loaded? When I say preload, I mean the 'new QDialog(..)...' process. That seems to be where the latency is as then that constructor begins laying out all the components and so on. the .show() isn't the issue as that runs instantly.

QCustomDialog * customDialog = new QCustomDialog(); // the latency
customDialog->show(); //not the latency

class QCustomDialog {
  QCustomDialog::QCustomDialog() {
   //creation of many nesscary widgets and added to the dialog
   QLabel * lab = new QLabel("Label 1");
  ...
 };

 
};
1

There are 1 answers

0
Silas Parker On

If you just need to let the user know the application is starting, and it takes a few seconds before the main window loads, you could use QSplashScreen.

This allows you to display an image while the main window loads. If the application takes more than a few seconds, and it makes sense for your application, you can also use QSplashScreen::message() to display messages as different parts of the app are loading.