我有一个带有QMdiArea
. 在当前活动的子窗口中,有一些传入和传出信号连接到小部件。每当活动子窗口更改时,我想断开与先前活动小部件的所有连接并连接到新激活的小部件。像这样:
//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;
}
子窗口可能发生更改,因为先前的子窗口已被用户关闭,因此不再存在/被QMdiArea
. 在这种情况下,我将调用mPreviouslyActiveWidget
指向已删除对象的断开连接函数。这是一个问题吗?调用会简单地失败并返回false
还是未定义?