原代码:
//如果登录成功
{
index mainForm;
mainForm.show();
this->hide();
}
主窗口一闪而过
修改为:
//如果登录成功
{
index mainForm = new inde();
mainForm.show();
this->hide();
}
程序报错
修改为:
//如果登录成功
{
index *mainForm;
mainForm = new index();
mainForm->show();
this->hide();
}
成功显示主窗口。
总结:
index mainForm;
mainForm.show();
mainForm创建在stack上,生命期是大括号内mainForm.show();
index *mainForm;
mainForm = new index();
mainForm = new index();
mainForm 通过new创建在heap上, 在程序退出时才会被析构
本文探讨了在登录成功后正确显示主窗口的方法。通过调整代码,将主窗口对象从堆栈移动到堆上创建,解决了主窗口一闪而过的问题。
7154

被折叠的 条评论
为什么被折叠?



