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 by qHash() 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. a QStringuse the QCryptographicHash 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());
    


  • @sneubert

    Hi sneubert,

    thanks very much for your reply. I was using it is store passwords which has now caused problems for me. I will do as you have recommended.

    Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.