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);
}
model = new QSqlTableModel;
model->setTable("tab");
model->select();
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsRemoved(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()
{
QSqlRecord record = model->record();
model->insertRecord(-1, record);
}
void ETest::deleteme()
{
model->removeRow(model->rowCount() - 1);
}
To copy to clipboard, switch view to plain text mode
When I use OnManualSubmit as strategy it is perfect:
{
...
if (d->strategy == OnFieldChange || d->strategy == OnRowChange)
return submit();
{
...
switch (d->strategy) {
case OnFieldChange:
case OnRowChange:
...
select();
bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record)
{
...
if (d->strategy == OnFieldChange || d->strategy == OnRowChange)
return submit();
bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
...
switch (d->strategy) {
case OnFieldChange:
case OnRowChange:
...
select();
To copy to clipboard, switch view to plain text mode
I suppose this is a wanted behavior but it makes rowsInserted and rowsRemoved signals very hard to use.
Bookmarks