PDA

View Full Version : qhash with custom class



dognzhe
2nd June 2009, 05:38
class Tank : public QObject, public QGraphicsItem
{
Q_OBJECT

public:
Tank(qint16 id,QObject *parent=0,QGraphicsScene *scene=0);
~Tank();
qint16 getTankId(){return tankId;}
private:
qint16 tankId;
};

inline uint qHash(const Tank &key){

return qHash(key.getTankId());
}

it give me a error:

error C2662: 'Tank::getTankId' : cannot convert 'this' pointer from 'const Tank' to 'Tank &' Conversion loses qualifiers

i have followed the examples in doc. I don't know what the hell going on...

any idea
thanks

kwisp
2nd June 2009, 06:30
dognzhe,
I think it is no good idea to use qHash name of function in your class, becouse there are many overloaded library`s function named qHash. I think it`s uncomfortably.
May be getHash?


Conversion loses qualifiers
I think, if you use const class reference (const Tank&), you can use const qualifier for it.



qint16& getTankId(){return tankId;}
qint16 getTankId() const {return tankId;}