Question

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();
       }
   }
Was it helpful?

Solution

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();

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top