scott_hollen
12th May 2011, 17:42
I feel like I keep stumbling on hard things to solve with simple code. I have 2 models, one a child of another, and the user of my app can delete a parent record, and subsequent child records. The problem is -- my model->removeRow command comes back as TRUE but no rows are removed from the model or the database even though I've performed a submitAll(). I count the rows in the child model before and it comes back with a count of 2, and after the removeRows() it's still equal to 2.
The models are defined such that selecting the parent filters the child model. And adding rows works fine.
Anyone have a thought? Thanks! (oh, and the qDebug() commands are just temporary for better error handling after I get it working)
void MainWindow::on_DeleleRegionPB_clicked()
{
int region_index;
region_index = regionmapper->currentIndex ();
qDebug() << flowlinemodel->rowCount ();
if (!flowlinemodel->removeRows (0, flowlinemodel->rowCount ()))
qDebug() << "Not able to delete flowline rows";
else
qDebug() << "woo-Who!";
// for (int i = 0; i < flowlinemodel->rowCount (); i++)
// {
// if (!flowlinemodel->removeRow (i))
// qDebug() << "issues";
// }
flowlinemodel->submitAll ();
qDebug() << flowlinemodel->rowCount ();
if (!regionmodel->removeRow (region_index))
qDebug() << "Not able to remove Region row";
if (region_index > 0)
regionmapper->setCurrentIndex (region_index - 1);
else
regionmapper->setCurrentIndex (region_index);
refresh_RegionView ();
set_Next_Previous_buttons();
}
scott
The models are defined such that selecting the parent filters the child model. And adding rows works fine.
Anyone have a thought? Thanks! (oh, and the qDebug() commands are just temporary for better error handling after I get it working)
void MainWindow::on_DeleleRegionPB_clicked()
{
int region_index;
region_index = regionmapper->currentIndex ();
qDebug() << flowlinemodel->rowCount ();
if (!flowlinemodel->removeRows (0, flowlinemodel->rowCount ()))
qDebug() << "Not able to delete flowline rows";
else
qDebug() << "woo-Who!";
// for (int i = 0; i < flowlinemodel->rowCount (); i++)
// {
// if (!flowlinemodel->removeRow (i))
// qDebug() << "issues";
// }
flowlinemodel->submitAll ();
qDebug() << flowlinemodel->rowCount ();
if (!regionmodel->removeRow (region_index))
qDebug() << "Not able to remove Region row";
if (region_index > 0)
regionmapper->setCurrentIndex (region_index - 1);
else
regionmapper->setCurrentIndex (region_index);
refresh_RegionView ();
set_Next_Previous_buttons();
}
scott