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.

Qt Code:
  1. 114 QVariant RDDSModel::data(const QModelIndex &index, int role) const
  2. 115 {
  3. 116 if (role == Qt::TextAlignmentRole)
  4.  
  5. 117 return Qt::AlignCenter;
  6. 118
  7. 119 ModelItem* pItem;
  8. 120 if(role == Qt::DisplayRole){
  9. 121 if(index.isValid())
  10. 122 pItem = static_cast<ModelItem*>(index.internalPointer());
  11. 123 else
  12. 124 pItem = pRoot;
  13. 125 return pItem->getData(index.column());
  14. 126 }
  15. 127 return QVariant();
  16. 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...

Qt Code:
  1. 427 template <typename T>
  2. 428 inline const T &QVector<T>::at(int i) const
  3. 429 { Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::at", "index out of range");
  4. 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.