PDA

View Full Version : Problem in activating a combobox at run time.



Niamita
5th March 2012, 09:56
Hi all
I am activating combobox at run time in following slot

list_combobox.clear();
for(int i=0; i<obj_schedule_table->rowCount(); i++)
{
QWidget *widget1;
widget1 = obj_schedule_table->cellWidget(i,3);
QComboBox *combo = (QComboBox*)widget1->children().at(1);
combo->setEditable(false);
list_combobox<<combo;
}
signalMapper_selection = new QSignalMapper(this);
for(int i=0; i<list_combobox.size(); i++)
{
signalMapper_selection->setMapping(list_combobox.at(i), i);
connect(list_combobox.at(i), SIGNAL(activated(QString)), signalMapper_selection, SLOT (map()));
connect(signalMapper_selection, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
}

this slot is called on clicking a button "edit"

in remove_row slot i again connect these combobox to appropriate slots


signalMapper_selection = new QSignalMapper(this);
QLineEdit *line_edit = (QLineEdit *)obj_schedule_table->cellWidget(index,0);
disconnect(list_combobox.at(index),0,0,0);
obj_schedule_table->removeRow(index);
list_combobox.removeAt(index);
for(int i=0; i<obj_schedule_table->rowCount(); i++)
{
signalMapper_selection->setMapping(list_combobox.at(i), i);
connect(list_combobox.at(i), SIGNAL(activated(QString)), signalMapper_selection, SLOT (map()));
connect(signalMapper_selection, SIGNAL(mapped(int)), this, SLOT(set_item_combobox_type(int)));
}

When i remove a row and than activate a combobox in row below than that row it give segmantaion fault while working fine above the removed row.

Please help me what i am doing wrong.

zgulser
5th March 2012, 13:36
you probably use the row that you just erased.

or it may be a deal of multithreading if you have.

Niamita
5th March 2012, 13:38
how i have to solve this problrm can you give some code example

wysota
5th March 2012, 13:55
Your code is very error prone (like static casting to QComboBox). Maybe try simplifying it first to make sure something else doesn't affect it.

mentalmushroom
5th March 2012, 14:22
When i remove a row and than activate a combobox in row below than that row it give segmantaion fault while working fine above the removed row
It is difficult to understand what is going on there, but a common mistake is to use the same row index as it was before deletion, but keep in mind when you delete an item everything below it will have indexes decreased by one.

zgulser
5th March 2012, 15:30
hi again,

Can you debug the code and tell us the line number where does the error excatly occur?