Hello,
I have a QAbstractListModel subclass which has a QList with objects of type "struct Foo". For a custom paint job, I use QStyledItemDelegates for the view. Inside its paint() method, I'd like to handle the real object behind the item directly. So I tried getting it by casting the internal pointer of the model index. This will compile, but only yield 0.

Qt Code:
  1. Foo *f = static_cast<Foo*>(index.internalPointer());
To copy to clipboard, switch view to plain text mode 

The problem here is, that the internal pointer is already 0. In the past I successfully used static casts on internal pointers.

On the other hand, using the model from the index and a custom method in the model works quite well. Yet, this solution looks rather long-winded.

Qt Code:
  1. Foo *f = ((FooModel*)index.model()).fooByIndex(index);
  2.  
  3. // Model definiton (excerpt)
  4. class FooModel : public QAbstractListModel
  5. {
  6. public:
  7. Foo *fooByIndex(const QModelIndex &index);
  8. }
To copy to clipboard, switch view to plain text mode 

Am I missing something here or is the internal pointer supposed to be null?


Andreas