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. Removing Rows from the QAbstractListModel , which is populated to QML.
Forum Updated to NodeBB v4.3 + New Features

Removing Rows from the QAbstractListModel , which is populated to QML.

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.9k 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.
  • B Offline
    B Offline
    basha92
    wrote on last edited by
    #1

    Hi ALL,

    I am able to populated items to QML from Qt using QAbstractListModel.
    When i am trying to clear items from the QHash<QString, QString> Results;
    using following function it is not getting reflected on the QML.

    @void AutoIdentViewModel::clear()
    {
    beginRemoveRows(QModelIndex(), 0, Results.size());
    identResults.clear();
    endRemoveRows();--
    }@

    I am calling above function before inserting items in to the model in C++.
    This function is called when i navigate from one page to another.

    Where am i doing wrong ?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      AFAIK, if you are using beginRemoveRows then you need to do it in removeRows(). Something like this
      @
      bool ListModel::removeRows(int row, int count, const QModelIndex &index)
      {
      beginRemoveRows(index, row, row + count - 1);
      identResults.clear();
      endRemoveRows();
      return true;
      }
      @

      Another way would be to use beginResetModel()
      @
      bool ListModel::clearAll()
      {
      beginResetModel();
      identResults.clear();
      endResetModel();
      return true;
      }
      @

      157

      1 Reply Last reply
      0
      • B Offline
        B Offline
        basha92
        wrote on last edited by
        #3

        Hi P3c0,

        The issue was ,i am clearing the QHash before processing for Data which will hit the data base.

        Thanks for swift reply.

        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