Unsolved 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 functionvoid 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; }
-
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 ?
-
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 -
Also, your correction worked, thanks a lot
-
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
-
Aren't you already deleting data in your list ?