I have a QHash of items I want to display in a QTableView. So I need a model. The MyClass has an internal id, which is used to insert into the map. Something like this:
// when adding a new item
my_super_hash[item->id] = item;
When implementing the model I found that all the methods in the model talk about the "index" which was clicked (or whatever...).
Can anyone remomend me how to map between the QHash and the model? (QHash which is key based, and the model is index based).
Option 1 - not ideal
One option is to create at startup a list which maps between the index to the key:
int i = 0;
foreach( MyClass* c, my_super_hash )
conversion[i] = c->id
Now inside the models re-implementation methods, I use
int key = conversion[index.row()];
MyClass * value = my_super_hash[key];
This idea seems messy, and I want a better implementation.