Results 1 to 2 of 2

Thread: QHash<float,int> and `qHash(const float&)' is ambiguous error

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QHash<float,int> and `qHash(const float&)' is ambiguous error

    Hi
    The following code gives error.
    Qt Code:
    1. QHash<float,int> hash;
    2. hash.insert(-1.5,1);
    3.  
    4. /usr/local/Trolltech/Qt-4.4.2/include/QtCore/qhash.h:838: error: call of overloaded `qHash(const float&)' is ambiguous
    To copy to clipboard, switch view to plain text mode 

    Where as if i use QMap instead of QHash such as

    Qt Code:
    1. QMap<float,int> mmap;
    2. mmap.insert(-1.5,1);
    To copy to clipboard, switch view to plain text mode 

    then the code works fine.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHash<float,int> and `qHash(const float&)' is ambiguous error

    From QHash docs:
    Here's a list of the C++ and Qt types that can serve as keys in a QHash: any integer type (char, unsigned long, etc.), any pointer type, QChar, QString, and QByteArray. For all of these, the <QHash> header defines a qHash() function that computes an adequate hash value. If you want to use other types as the key, make sure that you provide operator==() and a qHash() implementation.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    babu198649 (12th February 2009)

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.