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:
if(!ui->grdVisuals->itemAtPosition(row,x)->isEmpty()){
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:
void MainWindow
::on_EfectChoice_ValueChanged(QString Effect
){ int row
= QObject::sender()->property
("Row").
toInt();
//get the row number for(int x=1;x<ui->grdVisuals->columnCount();x++){ //loop all the row items except the first one
if(!ui->grdVisuals->itemAtPosition(row,x)->isEmpty()){
QComboBox* cboVar
= qobject_cast<QComboBox
*>
(ui
->grdVisuals
->itemAtPosition
(row,x
)->widget
());
if(cboVar){//remove the widget
ui->grdVisuals->removeWidget(cboVar);
ui->grdVisuals->removeItem(ui->grdVisuals->itemAtPosition(row,x));
cboVar->setParent(NULL);
delete cboVar;
}
}
}
for(int i=0;i < GLOutput->VisualList.count();i++){//loop the Visuals list to retrieve effect data
if(GLOutput->VisualList.at(i).Visual == Effect){
for(int a=0; a<GLOutput->VisualList.at(i).ArgCount;a++){//create a new combobox for each argument of the effect
InputType->setMinimumWidth(200);
ui->grdVisuals->addWidget(InputType,row,a+1,1,1,Qt::AlignLeft);
}
}
}
}
void MainWindow::on_EfectChoice_ValueChanged(QString Effect){
int row = QObject::sender()->property("Row").toInt(); //get the row number
for(int x=1;x<ui->grdVisuals->columnCount();x++){ //loop all the row items except the first one
if(!ui->grdVisuals->itemAtPosition(row,x)->isEmpty()){
QComboBox* cboVar = qobject_cast<QComboBox*>(ui->grdVisuals->itemAtPosition(row,x)->widget());
if(cboVar){//remove the widget
ui->grdVisuals->removeWidget(cboVar);
ui->grdVisuals->removeItem(ui->grdVisuals->itemAtPosition(row,x));
cboVar->setParent(NULL);
delete cboVar;
}
}
}
for(int i=0;i < GLOutput->VisualList.count();i++){//loop the Visuals list to retrieve effect data
if(GLOutput->VisualList.at(i).Visual == Effect){
for(int a=0; a<GLOutput->VisualList.at(i).ArgCount;a++){//create a new combobox for each argument of the effect
QComboBox* InputType = new QComboBox;
InputType->setMinimumWidth(200);
ui->grdVisuals->addWidget(InputType,row,a+1,1,1,Qt::AlignLeft);
}
}
}
}
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.
Bookmarks