[Solved] Show a modal QDialog just after MainWindow appears
I'm a newbie on QT. I try to build a QT Desktop application with QT 5.3.
I need to open a Modal Dialog juste after MainWindow appears (login dialog).
I try this:
LoginDialog *login = new LoginDialog(this);
if (login->exec() != QDialog::Accepted)
But I have two problem:
1/ The dialog is show before the MainWindow
2/ When the login dialog don't return "Accepted" the application hang...
Do you have any idea?
Thanks for your help.
[andreyc EDIT: added @ around code]
quick solution could be using showEvent to start a Timer (for example 100ms) and open the login page in connected slot
[quote author="mcosta" date="1401291075"]Hi,
quick solution could be using showEvent to start a Timer (for example 100ms) and open the login page in connected slot[/quote]
I thought about it but I thought there was a "cleaner" solution.
btw it works.
a simpler solution could be start a single shot timer in Window constructor with interval set to 0. In this way the slot will be processed after all pending events (including showEvent())
MainWindow::MainWindow(QWidget* w) ...
QTimer::singleShot(0, this, SLOT(openLoginDialog()));
QTimer::singleShot() is best solution definitelly. I'm using that whenever I need to execute something right after current event.
Also, you can create your own custom event and pass it to the widget, so you'll get almost same result. It is important that in such solutions there's no need for sleep or timeouts, it just flows and never makes troubles (of course if you know what you're doing).