Important: Please read the Qt Code of Conduct -

ASSERT: "last < rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp, line 2782

  • Hello,
    What does the above error mean in qt,
    I have a QList which I'm trying to delete from, the error occurs only when I'm trying to delete the last item in a QList after I delete an item at the top.
    When I start my deleting from the last item, no error occurs.
    And also, after the error pops out, when I try to delete it again, everything deletes fine,
    The code fragment below is my remove function

    void Model::remove(int index){
        if(index < 0 || index > m_entries.count()){
        emit beginRemoveRows(QModelIndex(), index, index);
        emit endRemoveRows();    
        emit rowCountChanged(m_entries.count());    
        qDebug()<<m_entries.count()<<"From qt";
        qDebug()<<"Before the helper function"<<m_entries.count();;
        for(int i =0;i<m_entries.count();++i){
        qDebug()<<"After the helper function"<<m_entries.count();
        for(int i =0;i<m_entries.count();++i){

    And the code fragment below is my helper function,

    void Model::helperFunction(){
        QList<Entry> tempList;
        for(int i = 0;i< m_entries.count();++i){
            QString titleTemp =;
            QDate dateTemp =;
            QTime timeTemp =;
            QString noteTemp =;
            QString importantTemp =;
            Entry temp(titleTemp,dateTemp,timeTemp,noteTemp,importantTemp,i);
        m_entries = tempList;

  • Lifetime Qt Champion


    From the looks of it, you are not done removing rows before your helperFunction as you are completely recreating your data structure. You should move both signal emit statements at the bottom of your remove method.

    On a side note, why not give your Entry object a method to allow to update that "i" value whatever it represents ? It would be less intrusive that rebuilding the complete list every time you change something in it. Also, why do you need to make that value match the position in the list ?

  • I have a Model (a QAbstractItemModel) been used in qml, The model is being passed through different delegatemodels for different listviews, I didn't find a way in which when an element is deleted from a particular listView it deletes from all the other listViews. - I asked in this link about it

  • Also, your correction worked, thanks a lot

  • Lifetime Qt Champion

    Well, you are modifying your internal data so you need to emit dataChanged when doing that otherwise the view won't react.

  • The problem is i'm not finding the way to get the appropriate index to be deleted

  • Lifetime Qt Champion

    Aren't you already deleting data in your list ?

Log in to reply