View Full Version : Update View when deteting record the Model
aguleo
4th December 2013, 10:01
Hi,
I'm using QSqlTableModel with a QTableView on Qt5.
When i delete a record ...
model->removeRows(view->currentIndex().row(), 1);
... i get a exclamation mark in the empty line.
I solved this by using...
model->select();
Is this the best approach?
Showldn't the view update autommaticaly?
aamer4yu
4th December 2013, 10:19
Where exactly do you get the exclamation mark ? In the view ?
Also are you using QAbstractItemModel::beginRemoveRows and QAbstractItemModel::endRemoveRows while removing the rows ?
anda_skoa
4th December 2013, 10:32
Maybe you have to call submit() after deleting the rows?
Cheers,
_
aguleo
4th December 2013, 10:34
Here ... in the view:
9837
ChrisW67
5th December 2013, 00:21
You get the "!" in the row header indicating that the row has been scheduled for deletion. The model will not actually remove the row from the database until QSqlTableModel::submit() or QSqlTableModel::submitAll() is called on the model (depends on the model edit strategy) directly or indirectly. I suspect that if you call select() without submit() the changes are likely to be discarded not committed, but I have not done the experiment.
aguleo
5th December 2013, 17:41
The only way i managed to make it work was with the model.select();
I have not tried the aamer4yu's tip but, for me, the question in this point is why it worked with Qt 4 but not with Qt5!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.