PDA

View Full Version : How to close first windows , and open different window but in the same application (l



umen
26th May 2011, 06:07
Hello all
Until now I was developing Qt MainWindow and always stay in this window , changing the content with QStackedWidget
But now I need to do something like to skype , the flow is
user open first window the login window after successful login , the window closes
And new different window opens with the user friends , now maybe it’s the same first window
That changed its look totally .. I don’t know.
How I manage this in Qt ?

Santosh Reddy
26th May 2011, 06:32
it should be simple, once user logs in create a new window, and close the existing one.


void MainWindow::logInOk(void)
{
QWidget* new_window = new NewWindow("Username"); //you can have NewWindow based off QMainWindow.. any other QWidget() based class, or QWidget itself

this.close(); //to destroy
//this.hide(); // to reuse it sometime later;
}

high_flyer
26th May 2011, 13:25
The suggestion in the post above is dangerous, and should NOT be done, since after MainWindow is destroyed and you get a dangling pointer, and a leak.

One way is to start with the main window hidden (but alive) and show a login dialog (which is NOT a child of the main window) and connect the finished() signal to MainWindow show() slot.

Santosh Reddy
26th May 2011, 13:29
The suggestion in the post above is dangerous, and should NOT be done, since after MainWindow is destroyed and you get a dangling pointer, and a leak.

Yes, I agree on this