QModelIndex invalid when returning from a dialog
-
Hi all,
in my project I've got a table view and I want to edit some rows using a qdialog subclass. In the dialog I've placed a qdatawidgetmapper to map wigets, and the submit policy is manual.
Now when the user clicks the save button on the dialog something like the following happens:@
qDebug() << "Current model row index is " << widgetMapper->currentIndex();
tableView->selectRow( widgetMapper->currentIndex() );
qDebug() << "Selected row " << tableView->currentIndex().row();
qDebug() << "Index is valid " << tableView->currentIndex().isValid();@where tableview is an instance of a QTableView, widgetmapper is an instance of the QDataWidgetMapper.
Now the outputs presents the following:@Current model row index is 3
Selected row -1
Index is valid false @So I'm editing the row number 3 of the table model, I want to select again such row when the dialog hides but suddenly the model index becomes invalid. Of course the widget mapper and the table view share the same QSqlRelationTableModel instance.
Can anybody give me an hint? -
I think I get it: the problem seems to be that the qdatawidgetmapper::submit() method invalidates (?) the currentIndex or something alike.
In fact the following piece of code works fine:@int modelIndex = widgetMapper->currentIndex();
retVal = widgetMapper->submit();
// emphasize the current record
tableView->selectRow( modelIndex );@while the following is not working:
@
retVal = widgetMapper->submit();
// emphasize the current record
ableView->selectRow( widgetMapper->currentIndex() );
@The difference is that in the working code the current index of the qdatawidgetmapper is hold before the actual submit, so I guess the submit produces something on the widget mapper or the model itself that prevents the selection of such index. It is still not clear to me what really happens, can anybody explain better where the problem is?