Dialog does not display when main window loads
I am new to programming in the mainwindow.cpp for the qt designer mainwindow.ui file. In the mainwindow.cpp file, the code completion does not work for the dialog. ui->dialog does nothing when typed in at the MainWindow::MainWindow(QWidget *parent) :.
I am trying to display the dialog.ui as a child of mainwindow.ui. I would like the dialog to load in front of the mainwindow as soon as the program loads. can i have a working example that i could type into the mainwindow.cpp please.
Dialog::Dialog(QWidget *parent) :
MainWindow::MainWindow(QWidget *parent) :
int main(int argc, char *argv)
QApplication a(argc, argv);
chernetsov0 last edited by
You actually need to change everything for this to work. So try some reading of manuals, I suppose.
Are you looking for a Splash screen?
Showing a dialog while something other creates and displays is not possible. You can show a mode less dialog, but to get this, you need a running event loop. The main window is typically created before the event loop runs.
yes, i am trying for a splash screen. I would like it to load in front of the main form as soon as the program loads. are you saying that is not possible without an event loop?
I might be able to get it running but i need to know how to set the splash screen form as the child of the mainwindow form and coded for the mainwindow.cpp file. Can i have help in this please or will i still need an event loop?
If you need a splash screen use QSplashScreen.
But it will be a top level window and not part of the main window.
If you want to show the main window first and then load your stuff, use a single shot timer and do it after displaying the main window.
Eddy last edited by
There is a splash screen example in chapter 3 of the official Qt book, which you can get "here":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip.
You can also look to the "docs of QSplashScreen":http://doc.qt.nokia.com/4.7/qsplashscreen.html#details
thank you Gerolf. I will read the QSplashScreen doc.
I managed to get the Dialog form loaded, but the Dialog loaded behind the MainWindow. Is this because I need that event loop? Also, the programs loads up as if I have two programs. Maybe because I did not set the Dialog as the child of the parent? Could I have an example on how to set the child up. thank you
[quote author="Eddy" date="1312179551"]There is a splash screen example in chapter 3 of the official Qt book, which you can get "here":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip.[/quote]
You should read a bit more introduction to Qt. Parent child relations are an absolute basic thing and you will need it.