PDA

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



babu198649
10th February 2009, 08:28
Hi
The following code gives error.

QHash<float,int> hash;
hash.insert(-1.5,1);

/usr/local/Trolltech/Qt-4.4.2/include/QtCore/qhash.h:838: error: call of overloaded `qHash(const float&)' is ambiguous


Where as if i use QMap instead of QHash such as


QMap<float,int> mmap;
mmap.insert(-1.5,1);

then the code works fine.

jpn
10th February 2009, 10:42
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.