how to provide a global qHash() for QSet
Solved
General and Desktop
-
I would like to create a QSet to contain unassignable value.
Thus, I must provide operator==(), and a global qHash() function.But there is something wrong with my qHash().here is my code:
entity.h
struct CVexOnSec { CVexOnSec(QVector3D P){ pos = P; } QVector3D pos; bool operator == (const CVexOnSec &vex) const { return (pos == vex.pos); } };
entity.cpp
inline uint qHash(const CVexOnSec &t, uint seed) { return qHash(t.pos.x()); }
and the error is error C2665.
located in the code in qhash.h:template<typename T> inline uint qHash(const T &t, uint seed) Q_DECL_NOEXCEPT_EXPR(noexcept(qHash(t))) { return (qHash(t) ^ seed); }
what's wrong with my qHash() , and how can I implement it correctly?
-
Hi
in the sample
http://doc.qt.io/qt-5/qhash.html#qhashit uses 2 parameters for the global qHash
return qHash(key.name(), seed)and
template<typename T> inline uint qHash(const T &t, uint seed)
seem to want 2.So my guess u need a seed :)