Results 1 to 2 of 2

Thread: qhash with custom class

  1. #1
    Join Date
    May 2009
    Posts
    38
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation qhash with custom class

    Qt Code:
    1. class Tank : public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Tank(qint16 id,QObject *parent=0,QGraphicsScene *scene=0);
    7. ~Tank();
    8. qint16 getTankId(){return tankId;}
    9. private:
    10. qint16 tankId;
    11. };
    12.  
    13. inline uint qHash(const Tank &key){
    14.  
    15. return qHash(key.getTankId());
    16. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qhash with custom class

    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.

    Qt Code:
    1. qint16& getTankId(){return tankId;}
    2. qint16 getTankId() const {return tankId;}
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. custom class for tslib
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 28th April 2009, 13:15
  2. How to store custom class in QHash?
    By Misenko in forum Qt Programming
    Replies: 3
    Last Post: 7th August 2008, 08:57
  3. QListWidget inheriting custom class
    By phannent in forum Qt Tools
    Replies: 1
    Last Post: 4th August 2008, 14:39
  4. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.