I am currently working on a project where I have a situation I am trying to solve. I have a base class that has a QHash that stores some objects. Currently I have two derived classes. The problem is that for one derived class I would like the key to be a string and for the other I would like it to be an int. The logic in the base class will be the same regardless, just the key type is different. I know that the simplest answer is to just make the key a string and convert the int to a string in that derived class when I access it. I was trying to come up with a more elegant solution, but maybe thats just overthinking it.
A lot of the access happens through functions, but sometimes the derived class accesses the QHash directly. That could be changed though. I thought about overriding the calls in the derived class to accept an integer, then convert it and call the base class version.
I wasnt sure if there was any way to make the base class QHash have a generic key. The functions all take the key too, so they would have to follow the same pattern.