Solved How to avoid QMdiArea.subWindowActivate.window.widget() crash?
-
connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(subWindowActivate(QMdiSubWindow*))); void MainWindow::subWindowActivate(QMdiSubWindow *window) { qDebug() << window; // minimized crash, close last subwindow crash MdiChild *child = (MdiChild*)(window->widget()); label1->setText(child->path); label3->setText(child->scodec); }
-
do not call methods on null or dangling/invalid pointers.
C style downcast is always a bad idea.void MainWindow::subWindowActivate(QMdiSubWindow *window) { if(window){ MdiChild *child = qobject_cast<MdiChild*>(window->widget()); if(child){ label1->setText(child->path); label3->setText(child->scodec); } } }