I have a MainWindow
which calls the LoginWindow in the constructor. The LoginDialog
has a button to create an account which will create a QDialog
.
I wanted to hide the LoginDialog
while the Dialog for the new account is showing but somehow it crashes.
When I remove the first and last line of the function which hides and shows the LoginDialog
it's absolutely fine. Why does it crash with hide()
and show()
are called ?
void LoginDialog::createAccount()
{
// (-> will cause crash later) hide(); //Hides LoginDialog
QDialog dlg;
dlg.setGeometry( this->x(), this->y(), this->width(), this->height() );
QWidget* centralWidget = new QWidget( &dlg );
QVBoxLayout* l = new QVBoxLayout( centralWidget );
dlg.setLayout( l );
QLineEdit *dlgUser = new QLineEdit( centralWidget );
QLineEdit *dlgPass = new QLineEdit( centralWidget );
dlgPass->setEchoMode( QLineEdit::Password );
l->addWidget( new QLabel( tr("Username :"), centralWidget ) );
l->addWidget( dlgUser );
l->addWidget( new QLabel( tr("Password :"), centralWidget ) );
l->addWidget( dlgPass );
l->addWidget( new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, centralWidget ) );
if( dlg.exec() != QDialog::Rejected )
{
;
}
delete centralWidget;
// (-> will cause crash later) show(); //Show LoginDialog again
}
There are no errors, it just crashes unexpectedly and sometimes it exits with code (0).
When analyzing with the debugger and really going through every single step it doesn't crash. The LoginDialog
will be shown and it's not going to crash.