PDA

View Full Version : Reconnect problem



xgoan
8th November 2006, 10:46
Hi,

I have a QTableWidget with QTextBrowser inherit Widgets on its cells. But when I want to delete a Item I can't reconnect the rest of items.

The code of remove function is the next:

void Itinerario::on_eliminarToolButton_clicked(){
desconectarWaypoints();

for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));
if(item->selected()){
if(QMessageBox::question(this, "", "Esta seguro de que desea eliminar el Waypoint?",
QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes){
item->disconnect();
waypoints->removeRow(i);

setWindowModified(true);
}

return;
}
}
reconectarWaypoints();
}

The code of remove connections is:

void Itinerario::desconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));

item->disconnect();
}
}

And the code of reconnect connections finally is:

void Itinerario::reconectarWaypoints(){
for(int i=0;i<waypoints->rowCount();i++){
WaypointItem *item=static_cast<WaypointItem*>(waypoints->cellWidget(i, TEXTBROWSER_CELLITEM));

connect(item, SIGNAL(clicked(WaypointItem*, int)), SLOT(waypointClicked(WaypointItem*, int)));
connect(item, SIGNAL(doubleClick(WaypointItem*, int)), SLOT(waypointDoubleClicked(WaypointItem*, int)));
connect(item, SIGNAL(modifiedChange(bool)), parent(), SLOT(setWindowModified(bool)));
}
}

I want to reconnect because if I dont do remove-reconnect the connection of removed item appears to be here.

Thanks

tbscope
8th November 2006, 20:51
Not sure if I understand the problem.

If you delete an item, the connections that are left are wrong? Therefor you first disconnect them all and create new connections?

If so, it might be better to simplify and use QSignalMapper.


btw:
If I selected 100 items for removal, I get 100 dialogs asking me if I'm sure?
You might want to ask only once :)