场景
在当前页面MySenderPage,点击PushButton,跳转至MyReceivePage,通常会用到信号和槽实现
connect(button, &QPushButton::clicked, this, &MySenderPage::goToReceivePage);void MySenderPage::goToReceivePage()
{//另一个页面展示MyReceivePage w;w.show();this->hide();
}
如果跳转页面使用 MyReceivePage w; w.show(); 会出现页面闪退的情况
解决方法
初始化页面使用指针就可以解决这个问题,MyReceivePage *w = new MyReceivePage; w->show();
connect(button, &QPushButton::clicked, this, &MySenderPage::goToReceivePage);void MySenderPage::goToReceivePage()
{//使用指针MyReceivePage *w = new MyReceivePage;w->show();this->hide();
}
完美解决