Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Inconsistency between model and view after removing a row from a table
Forum Updated to NodeBB v4.3 + New Features

Inconsistency between model and view after removing a row from a table

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlmodel view progmodel-view
2 Posts 2 Posters 476 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
    Ahti
    wrote on 23 Jan 2020, 06:30 last edited by Ahti
    #1
    This post is deleted!
    S 1 Reply Last reply 23 Jan 2020, 06:51
    0
    • A Ahti
      23 Jan 2020, 06:30

      This post is deleted!

      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 Jan 2020, 06:51 last edited by
      #2

      @Ahti said in Inconsistency between model and view after removing a row from a table:

      JsonObject u_data;
      u_data.insert("id", model->record(index.row()).value(0).toInt());
      u_data.insert("name", model->record(index.row()).value(1).toString());
      if (role == Qt::DisplayRole)
      return u_data;

      That's inefficient. If you only support DisplayRole, then you can move that QJsonObject directly into that if statement.

      if (role == Qt::DisplayRole) {
        QJsonObject u_data;
        u_data.insert("id", model->record(index.row()).value(0).toInt());
        u_data.insert("name", model->record(index.row()).value(1).toString());
        return u_data;
      }
      

      Second, you should use the parent here, even if it is a flat list:

      beginRemoveRows(QModelIndex(), first, last);
      response = model->removeRow(first, QModelIndex());

      beginRemoveRows(parent, first, last);
      response = model->removeRow(first, parent);
      

      But why you get this strange behavior when removing - I don't know. Perhaps it has something to do with the fact that you have two models here - UseModel is a list model and your model variable is a QSqlTableModel (which inherits from the same base class as list model). Perhaps these calls get duplicated, although it is unlikely.

      Try adding some qDebug() calls into removeRows(), or run it through a debugger, to see what is happening.

      (Z(:^

      1 Reply Last reply
      1

      1/2

      23 Jan 2020, 06:30

      • Login

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