Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQueryModel, QSortFilterProxyModel, QTableView : show blank records after transaction()
Qt 6.11 is out! See what's new in the release blog

QSqlQueryModel, QSortFilterProxyModel, QTableView : show blank records after transaction()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antseq
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      antseq
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved