首先判断一下当前的布局是否为空,如果不为空,循环删除部件的布局代码如下,
ui->pWidgetParam中有许多控件的布局,然后得到当前控件的数量,然后删除
if (ui->pWidgetParam->layout() != nullptr)
{
while (ui->pWidgetParam->layout()->count())
{
QWidget* p = ui->pWidgetParam->layout()->itemAt(0)->widget();
p->setParent(NULL);
ui->pWidgetParam->layout()->removeWidget(p);
delete p;
}
delete ui->pWidgetParam->layout();
}