qHash in Qt5
-
I have just migrated a project from qt4.8.5 to qt5.4.1, and it appears that the resulting value of a call to qHash() in qt4.8.5 to qt5.4.1 return different results. For example:
qHash ( "Hello" ) in qt4.8.5 returns a different result to the same function call in qt5.4.1.
Can someone please advise on this?
Thanks
-
Hi htettey,
QHash
is a template class for storing key, value pairs. The hash returned byqHash()
is used for fast lookup and can change in every version of Qt. It´s not intended to be used as a hash to store a password for example.
If you want to have a hash of e.g. aQString
use theQCryptographicHash
class. You can choose the hash function to use.QCryptographicHash hashObject(QCryptographicHash::Sha256); hasObject.addData(QByteArray(QString("Hello").toStdString().c_str())); QByteArray hashResult(hashObject.result());
-
Hi htettey,
QHash
is a template class for storing key, value pairs. The hash returned byqHash()
is used for fast lookup and can change in every version of Qt. It´s not intended to be used as a hash to store a password for example.
If you want to have a hash of e.g. aQString
use theQCryptographicHash
class. You can choose the hash function to use.QCryptographicHash hashObject(QCryptographicHash::Sha256); hasObject.addData(QByteArray(QString("Hello").toStdString().c_str())); QByteArray hashResult(hashObject.result());