rowsInserted and rowsRemoved signals with QSqlTableModel
Hello,
I have a QSqlTableModel and its signals rowsInserted and rowsRemoved connected to print their parameters:
Code:
model->setTable("tab");
model->select();
connect(model,
SIGNAL(rowsInserted
(QModelIndex,
int,
int)),
connect(model,
SIGNAL(rowsRemoved
(QModelIndex,
int,
int)),
...
void ETest
::sourceRowsInserted(const QModelIndex &source_parent,
int start,
int end
) {
qDebug() << "rowsInserted" << start << end;
}
void ETest
::sourceRowsRemoved(const QModelIndex &source_parent,
int start,
int end
) {
qDebug() << "rowsRemoved" << start << end;
}
void ETest::addme()
{
model->insertRecord(-1, record);
}
void ETest::deleteme()
{
model->removeRow(model->rowCount() - 1);
}
When I use OnManualSubmit as strategy it is perfect:
output inserting the fourth row:
rowsInserted 3 3
output removing the fourth row:
rowsRemoved 3 3
But when I use OnFieldChange or OnManualSubmit:
output inserting the fourth row:
rowsInserted 3 3
rowsRemoved 0 3
rowsInserted 0 3
output removing the fourth row:
rowsRemoved 0 3
rowsInserted 0 2
Stepping into Qt, I've found a call to submit and select:
Code:
{
...
if (d->strategy == OnFieldChange || d->strategy == OnRowChange)
return submit();
{
...
switch (d->strategy) {
case OnFieldChange:
case OnRowChange:
...
select();
I suppose this is a wanted behavior but it makes rowsInserted and rowsRemoved signals very hard to use.
I need to make a simple ModelProxy to populate a tree view with a QSqlTableModel, how can I get a clean signal when a row is inserted or removed?