[SOLVED] How to delete QLabel and QwtSlider in a std::vector
-
wrote on 19 Jun 2014, 14:17 last edited by
I have a std::vector filled up with QLabel and QwtSlider pointers and I would like to delete the pointers but not the vector.
Here my code:
@QLabel sliderSimuVarLabel;
std::vector<QLabel> labelsSimuVarList;
std::vector<QwtSlider*> slidersSimuVarList;int num = 3;
for (int i=0; i<numSimuVars; ++i){sliderSimuVarLabel = new QLabel("Hello", Widg);
sliderSimuVarLabel->setFont(panelFont2);labelsSimuVarList.push_back(new QLabelWidg));
labelsSimuVarList[i]->setFont(panelFont2);slidersSimuVarList.push_back(new QwtSlider(Qt::Horizontal,Widg));
layoutSimuPanel->addWidget(sliderSimuVarLabel,i+7,0);
layoutSimuPanel->addWidget(slidersSimuVarList[i],i+7,1,1,5);
layoutSimuPanel->addWidget(labelsSimuVarList[i], i+7, 7);
}
@I don't know with which method delete the pointers: clear()? deleteLater()? others?
Thanks in advance
-
wrote on 19 Jun 2014, 14:24 last edited by
Why do want to delete the pointer? The Widg takes ownership of the created classes. The pointers may be removed when going out of scope.
BTW Which pointer do you want to remove? -
wrote on 19 Jun 2014, 14:36 last edited by
I would like to delete the pointers in order to replace them with others QLabel and QwtSlider, when user clicks a button. I would like to remove the pointers that point each QLabel and QwtSlider in the vector. I tried something like this:
@ if(sliderSimuVarLabel!=NULL ){
sliderSimuVarLabel->deleteLater();
labelsSimuVarList.clear();
slidersSimuVarList.clear();
}@or this:
@ if(sliderSimuVarLabel!=NULL){
sliderSimuVarLabel->deleteLater();for (int i=0; i>labelsSimuVarList.size();++i) { labelsSimuVarList[i]->deleteLater(); slidersSimuVarList[i]->deleteLater(); } }@
but I am looking for the most safe way to delete them...
-
wrote on 19 Jun 2014, 15:19 last edited by
1/4