I’m pulling my hair out on this one and it’s probably something simple, but I can’t find it. I initially sub-classed QAbstractItemModel and everything seemed to work fine. I made what appeared to be unrelated changes in a different .cpp file when the program started reporting an ASSERT error. I believe I changed everything back, to the state it was in when it was working properly and yet it still reported the same error.
Using the debugger, I stepped through the program and found the location where the problem was starting. Surprisingly it was transpiring in the pure virtual function “data†at the line where I was checking if the request was referencing the TextAlignmentRole - line 116 in the code listing.
115 {
116 if (role == Qt::TextAlignmentRole)
117 return Qt::AlignCenter;
118
119 ModelItem* pItem;
120 if(role == Qt::DisplayRole){
121 if(index.isValid())
122 pItem = static_cast<ModelItem*>(index.internalPointer());
123 else
124 pItem = pRoot;
125 return pItem->getData(index.column());
126 }
128 }
114 QVariant RDDSModel::data(const QModelIndex &index, int role) const
115 {
116 if (role == Qt::TextAlignmentRole)
117 return Qt::AlignCenter;
118
119 ModelItem* pItem;
120 if(role == Qt::DisplayRole){
121 if(index.isValid())
122 pItem = static_cast<ModelItem*>(index.internalPointer());
123 else
124 pItem = pRoot;
125 return pItem->getData(index.column());
126 }
127 return QVariant();
128 }
To copy to clipboard, switch view to plain text mode
The actual error message received is...
ASSERT failure in QVector<T>::at: "index out of range"
The debugger indicates that the error is being reported from qvector.h at line 429. Code shown...
427 template <typename T>
428 inline const T &QVector<T>::at(int i) const
429 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
430 return d->begin()[i]; }
427 template <typename T>
428 inline const T &QVector<T>::at(int i) const
429 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
430 return d->begin()[i]; }
To copy to clipboard, switch view to plain text mode
At this time, I fail to seen any connection to the error message and the code where the error originated. Any help on this issue would be highly appreciated.
Bookmarks