I have an application with a QMdiArea
. There's some incoming and outgoing signals connected to the widget in the currently active subwindow. Whenever the active subwindow changes I want to disconnect all the connections to the previously active widget and connect to the newly activated widget. As such:
//Function connected to QMdiArea::subWindowActivated...
void
MainWindow::SubWindowActivated(QMdiSubWindow* subWindow)
{
auto activeWidget{ qobject_cast<MyWidget*>(subWindow->widget()) };
if (activeWidget == mPreviouslyActiveWidget)
{
return;
}
//disconnect all incoming and outgoing signals between previously active widget and this.
disconnect(this, nullptr, mPreviouslyActiveWidget, nullptr);
disconnect(mPreviouslyActiveWidget, nullptr, this, nullptr);
//re-establish connections to activeWidget ... removed for brevity
mPreviouslyActiveWidget = activeWidget;
}
It's possible that the subwindow changed because the previous subwindow was closed by the user and thus no longer exists/is deleted by the QMdiArea
. In that case I would be calling the disconnect functions whith mPreviouslyActiveWidget
pointing to a deleted object. Is this a problem? Will the call simply fail and return false
or is this undefined ?