Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ASSERT: "last < rowCount(parent)" in file itemmodels\qabstractitemmodel.cpp, line 2782
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.1k 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
    Abdulmueez
    wrote on 20 Aug 2019, 20:46 last edited by Abdulmueez
    #1

    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()){
            return;
        }
        emit beginRemoveRows(QModelIndex(), index, index);
        m_entries.removeAt(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()<<m_entries.at(i).title()<< m_entries.at(i).position();
        }
        helperFunction();
        qDebug()<<"After the helper function"<<m_entries.count();
        for(int i =0;i<m_entries.count();++i){
            qDebug()<<m_entries.at(i).title()<< m_entries.at(i).position();
        }
    }
    
    

    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 = m_entries.at(i).title();
            QDate dateTemp = m_entries.at(i).date();
            QTime timeTemp = m_entries.at(i).time();
            QString noteTemp = m_entries.at(i).note();
            QString importantTemp = m_entries.at(i).important();
            Entry temp(titleTemp,dateTemp,timeTemp,noteTemp,importantTemp,i);
            tempList.append(temp);
        }
        m_entries = tempList;
    }
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Aug 2019, 20:55 last edited by
      #2

      Hi,

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • A Offline
        A Offline
        Abdulmueez
        wrote on 20 Aug 2019, 21:26 last edited by
        #3

        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.
        https://forum.qt.io/topic/106035/different-listviews-one-model - I asked in this link about it

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Abdulmueez
          wrote on 20 Aug 2019, 21:29 last edited by
          #4

          Also, your correction worked, thanks a lot

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 20 Aug 2019, 21:31 last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Abdulmueez
              wrote on 20 Aug 2019, 21:38 last edited by
              #6

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 21 Aug 2019, 20:29 last edited by
                #7

                Aren't you already deleting data in your list ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                1/7

                20 Aug 2019, 20:46

                • Login

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