The easiest way to do this is inherit from QHash
and provide an own template parameter:
template <typename T>
class MyHash : public QHash<quint8, T> { };
Example:
int main(int argc, char *argv[])
{
MyHash<QDate> testHash;
quint8 testKey = 123;
QDate testDate;
testHash.insert(testKey, testDate);
MyHash<QDate> testHash2(testHash);
qDebug() << testHash2.value(testKey); // outputs 'QDate("")'
}
About the placement of this typedef, it's hard to answer that if you don't know the full project.
Just put the definition in the header file which is most suitable in your opinion. Ask yourself if really the whole project needs that definition, or just a couple of files. If you e.g. have a data layer, only your data classes should directly include that file in their header files. Other classes will then automatically know it as soon as they include one of your data class headers.
If really every single class in your project shall use it, you could place it in an existing or a new definitions file in your project root and
- include that file in your precompiled header file, if you are using that, or
- check if your compiler supports a "Force Include" option.