QSqlQueryModel, QSortFilterProxyModel, QTableView : show blank records after transaction()
-
I've got one 'master' form displaying items('primary key' + 'description') from a database table.
It's seems to work OK:
@----------------------------
:private
QTableView *tblView;
QSqlQueryModel *sqlModel;
QSortFilterProxyModel *sqlProxy;QPushButton *btnInsert; QPushButton *btnEdit;
...
sqlModel->setQuery(mSqlSelect, database);sqlProxy->setSourceModel(sqlModel); tblView->resizeColumnsToContents(); tblView->setSortingEnabled(true); tblView->setAlternatingRowColors(true); tblView->setSelectionMode(QAbstractItemView::SingleSelection); tblView->setSelectionBehavior(QAbstractItemView::SelectRows); tblView->setModel(sqlProxy); tblView->selectRow(0); tblView->setFocus();
...
----------------------------@When a user clicks [edit] or [insert] buttons another (edit) form is presented to the user with all table fields, so then user can change them.
It's seems to work OK, but...If I simple call tableMapper->revert() or submit() the (edit) form closes, and going back do master form it still the same showing all records exactly as before (note: I have not implemented a 'refresh')
@
void EditForm::done(int result)
{
if (result == QDialog::Rejected) {
tableMapper->revert();
}
if (result == QDialog::Accepted) {
tableMapper->submit();
}
QDialog::done(result);
}@If I call tableMapper->submit() between transaction() and commit() the (edit) form closes, and going back do master form it automatically CHANGES (!?) and SHOWS all existing records BLANK (!?) (note: I have not implemented a 'refresh')
@
void EditForm::done(int result)
{
if (result == QDialog::Rejected) {
tableMapper->revert();
}if (result == QDialog::Accepted) { mDatabase.transaction();
tableMapper->submit();
mDatabase.commit();
}
QDialog::done(result);
}@I was not expecting that. I thought that with/or without transactions the edit form would close and going back to master form it would still the same, showing all records\ old values as before.
Can someone help me to understand why using transaction()/commit() on a second (supposed isolated) form makes the master (first) form records go to BLANK?
thanks in advance for any help.
-
My initial post was a big mess because I did not format my source with 'code' format. (Sorry for that, I won't forget in the future).
Additionally, I am using : QT 5.0.2 + MinGW 4.7 + 32 bits + ODBC driver + Windows 7 (32) + SQL Server 2012 Express.
Hope that someone could give me any hint / help / suggestion.
Thanks in advance.