tags:

views:

140

answers:

2
+1  Q: 

Qt4 login window

I am writing a login window in Qt.

When the users clicks on OK, it should close the login window, show a "Connecting to server..." Widget, and open the main window once the connecttoserver method has done its job.

However, the widget appears only when the main window is shown, and disappears immediately (it shouldn't even close!)

How do I solve this issue ?

void LoginWindow::blah()
   {
   close();

   QWidget widget;
   widget.show();

   //calls to the "connecttoserver method"

   Main *main = new Main(student->getInfo()[0], student->getInfo()[1], student->getInfo()[2], view);
   main->show();
       }
   }
+2  A: 

QWidget is declared as an automatic on the stack so it is destroyed when the method returns. You want to declare it on the heap instead:

QWidget *widget = new QWidget();
widget->show();
atomice
Thank you, now the window stays open.However, it still opens too late.While the connecttoserver method loads, no window is shown...
Klaus
It won't be visible on the screen until your application returns to the event loop.You can try calling qApp->processEvents() after widget->show() but this is just a hack and the window won't repaint properly (amongst other things).To solve the problem properly you want to i) make connecttoserver non-blocking or ii) call connectttoserver on a different thread.
atomice
Thank you, it works well now. I will take at look at threads in a while.
Klaus
A: 

In addition to atomice's answer, make sure you have set your application's quitOnLastWindowClosed to false, or else your application will terminate between closing your login window and opening your main window.

Bill