Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-38509

QSqlTableModel::selectRow does not refresh row in the model if the value in the last column is the same in old record and new record.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 5.2.0, 5.2.1
    • Fix Version/s: 5.3.0 RC1
    • Component/s: SQL Support
    • Labels:
      None
    • Environment:
      Windows, Mac, Linux
    • Commits:
      373d858812a84b48be482dd64ad9d248ab2d5b3c

      Description

      The QSqlTableModel::selectRow is supposed to refresh the row in the model if any column value in the record has changed in the underlying sqlite db (I am using sqlite, but the problem should be the same for other dbs). However, if the last column value is unchanged in the cache and the underlying db, then the row is not refreshed. Please see the logical error given below:

      bool QSqlTableModel::selectRow(int row)
      {
      :
      :
      :

      bool needsAddingToCache = !exists || d->cache.contains(row);

      if (!needsAddingToCache) {
      const QSqlRecord curValues = record(row);
      needsAddingToCache = curValues.count() != newValues.count();
      if (!needsAddingToCache) {
      // Look for changed values. Primary key fields are customarily first
      // and probably change less often than other fields, so start at the end.
      for (int f = curValues.count() - 1; f >= 0; --f)

      { -------------------> The if statement is missing a brace <----------------- if (curValues.value(f) != newValues.value(f)) needsAddingToCache = true; break; -------------------> The if statement is missing a brace <----------------- }

      }
      }

      if (needsAddingToCache)

      { d->cache[row].refresh(exists, newValues); emit headerDataChanged(Qt::Vertical, row, row); emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); }

      return true;
      }

      As shown above the if statement at qsqltablemodel.cpp:451 in Qt 5.2.0 is missing a brace so the control breaks out after comparing only the last column and so if the last column is unchanged the row is never refreshed.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            mabrand Mark Brand
            Reporter:
            rohitvkumar Rohit Valsakumar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes