我建了一个主窗口MainWindow::QMainWindow,
在MainWindow中定义了2个子窗口的指针,
private:
Widget1* a;
Widget2* b;
Widget1和Widget2都继承自QWidget
在主窗口的构造函数中实例化,
MainWindow::MainWindow()
{
a = new widget1(this);
b = new widget2(this);
}
void MainWindow::show1()
{
setCentralWidget(a);
}
void MainWindow::show2()
{
setCentralWidget(b);
}
show1和show2都是槽,
执行的时候,是先show1()然后show2()再show1()
但是第二次进入show1()时报错,跟踪发现第二次进入show1()时a的指针为不可用,a的在show2()执行过程中是存在的,在show2()方法执行后,进入show1()的信号发出前被析构,我没有对a进行close的操作,貌似是qt将其当作垃圾自动回收了
我想实现的操作是,a显示时b隐藏,b显示时a隐藏,但a、b都不销毁,请问各路高手有没有什么好的方法解决......