I'm using a QPair as a key, and I want to use another comparison function and not the given one.
I tried to derived QPair an use it as a key:
template <class T1, class T2>
struct stEvPairKey : QPair<T1, T2>
{
stEvPairKey() : QPair<T1, T2>() {}
stEvPairKey(const T1 &t1, const T2 &t2) : QPair<T1, T2>(t1, t2) {}
};
template <class T1, class T2>
bool operator==(const stEvPairKey<T1, T2> &p1, const stEvPairKey<T1, T2> &p2)
{
return (p1.first == p2.first) && (p1.second & p2.second);
}
template <class T1, class T2>
struct stEvPairKey : QPair<T1, T2>
{
stEvPairKey() : QPair<T1, T2>() {}
stEvPairKey(const T1 &t1, const T2 &t2) : QPair<T1, T2>(t1, t2) {}
};
template <class T1, class T2>
bool operator==(const stEvPairKey<T1, T2> &p1, const stEvPairKey<T1, T2> &p2)
{
return (p1.first == p2.first) && (p1.second & p2.second);
}
To copy to clipboard, switch view to plain text mode
and use this struct as a key:
QHash<stEvPairKey<int, unsigned long>, CMyClass*> m_hash;
QHash<stEvPairKey<int, unsigned long>, CMyClass*> m_hash;
To copy to clipboard, switch view to plain text mode
But never goes into my "operator==".
The function you give:
quint32 qHash(const Key &key);
quint32 qHash(const Key &key);
To copy to clipboard, switch view to plain text mode
is to compute the hash value for the key, but not to compare 2 keys.
What is wrong?
Thank you.
Bookmarks