I know this has been asked several times in different posts, however I am still not convinced that my implementation is the best solution.
I have a QVBoxLayout in which I add a QHBoxLayout which hold widgets. The QVBoxLayout by default is empty.
I delete all layouts widgets using this code, however the widgets can fire signals. Is this save? Also I would rather want to change it to a recursive function as shown in https://stackoverflow.com/questions/4272196/qt-remove-all-widgets-from-layout/7077340#=
QLayoutItem *child;
while ((child = ui->verticalLayoutAmplitude->takeAt(0)) != 0) {
QLayoutItem * subchild;
while ((subchild = child->layout()->takeAt(0)) != 0) {
delete subchild->widget();
delete subchild;
}
delete child->widget();
delete child;
}
What I do not understand is why it is so complicated.
Also the creation of the widgets could be different The parent layout can not be used in the creation of the widgets. Thus only the MainWindow as a parent class was inserted. I wonder what else should be inserted as a parent class?
for (int i = 0; i < parameterList.size(); ++i) {
QString valueName = parameterList.at(i);
double value = parameter(valueName);
QHBoxLayout * hLayout = new QHBoxLayout(this);
QDoubleSpinBox * spinbox = new QDoubleSpinBox();
QLabel * label = new QLabel();
label->setText(valueName);
spinbox->setValue(value);
hLayout->addWidget(label, 1);
hLayout->addWidget(spinbox, 3);
ui->verticalLayoutAmplitude->addLayout(hLayout);
}