Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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 ?


  • Moderators

    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;
    }
    @



  • Hi P3c0,

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

    Thanks for swift reply.


Log in to reply