I'm trying to dynamicly add and remove widgets to a gridlayout based on what the user selects in a combobox named EffectChoice. This works perfect if I select an effect with one argument(a new ComboBox is added) and then choose an effect with 0 arguments(the ComboBox is deleted). However, if I then select the effect with one argument again, Qt crashes at this line:
Qt Code:
  1. if(!ui->grdVisuals->itemAtPosition(row,x)->isEmpty()){
To copy to clipboard, switch view to plain text mode 
This is the full code of the combobox:
Qt Code:
  1. void MainWindow::on_EfectChoice_ValueChanged(QString Effect){
  2. int row = QObject::sender()->property("Row").toInt(); //get the row number
  3. for(int x=1;x<ui->grdVisuals->columnCount();x++){ //loop all the row items except the first one
  4. if(!ui->grdVisuals->itemAtPosition(row,x)->isEmpty()){
  5. QComboBox* cboVar = qobject_cast<QComboBox*>(ui->grdVisuals->itemAtPosition(row,x)->widget());
  6. if(cboVar){//remove the widget
  7. ui->grdVisuals->removeWidget(cboVar);
  8. ui->grdVisuals->removeItem(ui->grdVisuals->itemAtPosition(row,x));
  9. cboVar->setParent(NULL);
  10. delete cboVar;
  11. }
  12. }
  13. }
  14. for(int i=0;i < GLOutput->VisualList.count();i++){//loop the Visuals list to retrieve effect data
  15. if(GLOutput->VisualList.at(i).Visual == Effect){
  16. for(int a=0; a<GLOutput->VisualList.at(i).ArgCount;a++){//create a new combobox for each argument of the effect
  17. QComboBox* InputType = new QComboBox;
  18. InputType->setMinimumWidth(200);
  19. ui->grdVisuals->addWidget(InputType,row,a+1,1,1,Qt::AlignLeft);
  20. }
  21. }
  22. }
  23. }
To copy to clipboard, switch view to plain text mode 
I'd google it, but I don't really know what's causing it and what searchwords to use.