Showing a dialog at application startup
For my program, I need to pop up a dialog at first run so that the user can enter the directory where the data files are (they don't come with the program). I can look at my configuration file to decide whether or not to show the dialog - the question is where in my code to show it. If I put it in main() before app.exec(), the even loop won't have started yet, so it won't be responsive. I suspect there's an even handler in my main window class that I need to implement, but I can't figure out which one from the documentation.
The code path I think I need:
*Create main window
* run app.exec
* some even handler gets called
* show dialog
Re: Showing a dialog at application startup
In my opinion make ur own window class...
from main call the mainwindow. In the window class, keep a function to get input from the user as u expect. from the mainwindow constructor, call the function using QTimer::singleShot() .
This will display ur main window and also pop up the input dialog. After the input u can call some function to initialize ur data. This approach will help in case u later dont want to call the input dialog . You can still show the window without it.
Pseudo code :
Code:
main()
{
...
MainWindow window;
window.show();
return app.exec();
}
// mainwindow
{
MainWindow()
{
...
QTimer::singleshot(getInput
(),
0);
// call the input function using timer }
};
void MainWindow::getInput()
{
// pop dialog
// initialize variables
}
Re: Showing a dialog at application startup
A modal dialog spins its own event loop so you can put it in main().
Re: Showing a dialog at application startup
The QTimer::singleShot method looks like it will do what I need. Thanks!